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

    Tabs only in pages with sub routes

    Help
    navigation sub routes tabs
    2
    4
    1188
    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.
    • D
      D3myon last edited by

      Hi,

      I’ve got the following problem:

      I intend to use the side menu as the primary navigation and want to use tabs inside the navigation slot for sub routes (sub pages). So some pages with sub routes shall contain tabs and those without shall not.

      I could load different layouts, but I guess it’s not really best practice.

      Is there a proper way to realize this?

      Thank you very much.

      And Merry Christmas!

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

        One way I saw this was done was using the meta property of the routes. Something like this

        // router.js
        const routes = [
          {
            path: '/route',
            component: load('Component1'),
            meta: {
              tabs: [
                {
                  path: '/route/tab1',
                  component: 'Component2'
                },
                {
                  path: '/route/tab2',
                  component: 'Component3'
                }
              ]
            },
            children: [
              {
                path: 'tab1',
                component: load('Component2'),
                meta: {
                  tabs: [
                    {
                      path: '/route/tab1',
                      component: 'Component2'
                    },
                    {
                      path: '/route/tab2',
                      component: 'Component3'
                    }
                  ]
                }
              },
              {
                path: 'tab2',
                component: load('Component3'),
                meta: {
                  tabs: [
                    {
                      path: '/route/tab1',
                      component: 'Component2'
                    },
                    {
                      path: '/route/tab2',
                      component: 'Component3'
                    }
                  ]
                }
              }
            ]
          },
          {
            // no tabs
            path: '/route2',
            component: load('Component4')
          }
        ]
        
        <q-tabs v-if="$route.meta && $route.meta.tabs && $route.meta.tabs.length">
          ...
        </q-tabs>
        

        As this means a lot of repetition in router.js, you probably wan a function to help you with it.

        const pages = [
          {
            hash: 'route1',
            title: 'Main page',
            tabs: [
              {
                hash: 'tab1',
                title: 'Tab 1 Page'
              },
              {
                hash: 'tab2',
                title: 'Tab 2 Page'
              }
            ]
          },
          {
            hash: 'route1',
            title: 'Another Page'
          }
        ]
        const routes = []
        pages.forEach(page => {
          let route = {
            component: load(page.hash),
            path: page.hash,
            meta: {
              tabs: page.tabs
            }
          }
          if (page.tabs && page.tabs.length) {
            route.children = []
            page.tabs.forEach(tab => {
              route.children.push({
                component: load(tab.hash),
                path: tab.hash,
                meta: {
                  tabs: page.tabs
                }
              })
            })
          }
          routes.push(route)
        })
        // routes object now ready
        
        D 2 Replies Last reply Reply Quote 2
        • D
          D3myon @benoitranque last edited by

          @benoitranque thank you for your answer and time. I will try this solution this evening and revert after that.

          1 Reply Last reply Reply Quote 0
          • D
            D3myon @benoitranque last edited by

            @benoitranque So, I took a look now. This is exactly what I was looking for. Thank you so much.

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