No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Tip : Navigation links to External Urls

    Useful Tips (NEW)
    2
    2
    325
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      rab last edited by

      Navigation drawers often contain a mix of internal and external links.

      The following is working well for me:

      // generate nav links as a list of q-items
      <q-list>
        <q-item
          v-for="(item,id) in items" :key="id"
          exact
          tag="a"
          :to="item.to"
          :href="item.href"
          :target="item.target||'_'">
          <q-item-section>
            <q-item-label>
              {{ item.label }}
            </q-item-label>
          </q-item-section>
        </q-item>
      </q-list>
      

      You then provide data where items have either a to or an href:

      // the data
        data () {
          return {
            items: [
              { label: 'One',     to:   '/one'            },
              { label: 'Two',     to:   '/two'            },
              { label: 'Bing',    href: 'http://bing.com' }
            ]
        }}
      

      Please shout if this breaks something I should be aware or if there is an alternative recommended way.

      Hope it helps.

      1 Reply Last reply Reply Quote 0
      • beets
        beets last edited by

        Useful tip, you could also do something like this:

        // generate nav links as a list of q-items
        <q-list>
          <q-item
            v-for="(item,id) in items" :key="id"
            exact
            tag="a"
            v-bind="item">
            <q-item-section>
              <q-item-label>
                {{ item.label }}
              </q-item-label>
            </q-item-section>
          </q-item>
        </q-list>
        
        

        And bind all attributes to the item. Binding unused attributes like label usually isn’t a problem, if you wanted could also do:

        // the data
          data () {
            return {
              items: [
                { label: 'One',     attrs: { to:   '/one'  }          },
                { label: 'Two',     attrs: { to:   '/two'  }         },
                { label: 'Bing',    attrs: { href: 'http://bing.com', target: '_blank' } }
              ]
          }}
        

        And v-bind="item.attrs"

        1 Reply Last reply Reply Quote 0
        • First post
          Last post