Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Named Views and Nested Routes #1921

Closed
oixan opened this issue Dec 2, 2017 · 6 comments
Closed

Document Named Views and Nested Routes #1921

oixan opened this issue Dec 2, 2017 · 6 comments
Assignees
Labels

Comments

@oixan
Copy link

oixan commented Dec 2, 2017

Version

3.0.1

Reproduction link

Full problem Example
https://jsfiddle.net/oaxs8ek8/

Steps to reproduce

I have created a Homepage with 2 Named Views called for example RouteA and RouteB.
Now RouteA and RouteB have 2 other nested routes like so RouteA1 and RouteA2 - RouteB1 and RouteB2.

const router = new VueRouter({
  routes: [
    {
      path: '/',
      components: {
        RouteA : Bar,
        RouteB: Baz
      }
    }
  ]
})

this work very well for the first route but then i cant continue the routing chain for the 2 differente route since i cant only do this:

const router = new VueRouter({
  routes: [
    {
      path: '/',
      components: {
        RouteA : Bar,
        RouteB: Baz
      },
      children: [
        {
          path: '' // Load RouteA1 on RouteA
          component: UserProfile
        },
        {
          path: '', // Load RouteB1 on RouteB
          component: UserPosts
        }
      ]
    }
    }
  ]
})

There is no way to specify the different route.

A solution could be enable this for example:

const router = new VueRouter({
  routes: [
    {
      path: '/',
      components: {
        RouteA : {
                     path: ''
                     component: Bar,
                     children:{
                        ....
                     }
              },
        RouteB:  {
                     path: ''
                     component: Baz,
                     children:{
                        ....
                     }
      }
    }
  ]
})

What is expected?

The router should allow nested route with named view router

What is actually happening?

it's not routeing correctly

@posva
Copy link
Member

posva commented Dec 8, 2017

Hey, really sorry for the delay!

If you're using named views with nested views, you'll have to name the nested views as well because otherwise, you end up with 2 router-view components at the same time.

In your fiddle you have to add a name to one of them:

const Bar = { template: '<div>bar <router-view name="b"></router-view> </div>' }

And use that in the route definition:

{ path: '/',
      // a single route can define multiple named components
      // which will be rendered into <router-view>s with corresponding names.
      components: {
        default: Foo,
        a: Bar,
        b: Baz
      },
      children:[
      	{ path: '', components: { default: Foo2, b: Bar2 }},
      ]
    }

Here's a working version: https://jsfiddle.net/4xwnz3mg/

@posva posva closed this as completed Dec 8, 2017
@posva
Copy link
Member

posva commented Dec 8, 2017

This could be documented, so reopening this to track it

@posva posva reopened this Dec 8, 2017
@posva posva added the docs label Dec 8, 2017
@posva posva self-assigned this Dec 8, 2017
@posva posva changed the title Named Views and Nested Routes Problem Document Named Views and Nested Routes Dec 8, 2017
@oixan
Copy link
Author

oixan commented Dec 8, 2017

But with this methods how can i continue the chain with Bar 3 for example?

@posva
Copy link
Member

posva commented Dec 8, 2017

What Bar3? You mean adding another nested route to the children routes?

@oixan
Copy link
Author

oixan commented Dec 8, 2017

I mean adding in bar 2 another nested route bar 3

@posva
Copy link
Member

posva commented Dec 8, 2017

You add a children property to the path ''` in the children array. But nesting careful when nesting too many things, it complexifies the application structure a lot

posva added a commit that referenced this issue Dec 8, 2017
posva added a commit that referenced this issue Jan 10, 2018
* docs: add example of nested named routes

Closes #1921

* docs: add link of jsfiddle in note

* review

* [skip ci] review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants