-
-
Notifications
You must be signed in to change notification settings - Fork 5k
children named routes and empty path not rerendering #822
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
Comments
I was about to file an issue, but found this relevant thread. The point is, by using named routes (e.g. To be more clear, from the posted code by @nicolas-t : const router = new VueRouter({
routes: [
{
path: '/user/:id',
name: 'user', // name property is set on the parent route
component: User,
children: [
{
path: '',
component: UserProfile // by using named routes,
// this is not going to be rendered!
},
{
path: 'posts',
component: UserPosts
}
]
},
{
path: '',
component: Home,
}
]
}) |
@HashemQolami Out of curiosity, could you not just put |
As mentioned to @HashemQolami , if you include the name attribute on the child routes, this works. The documentation doesn't really mention anything about using the name property on parent routes. I guess the way to look at it is that the parent route is more of a container, rather than page - therefore not really a "route" in it's own right, so no name required. I updated your fiddle to give an example of what I mean. |
@creativeesprit It produces another bug sorta.. which I was thinking of creating a new issue for that. Consider the following snippet: <router-link :to="{name: 'home'}" exact>Home</router-link>
<router-link to="/user">/user (2) </router-link>
<router-link :to="{name: 'user'}">user (named route) (3) </router-link>
<router-view></router-view> const router = new VueRouter({
mode: 'history',
routes: [
{
path: '/user',
component: User,
children: [
{
path: '',
name: 'user',
component: UserHome
}
]
},
{
path: '',
name: 'home',
component: Home,
}
]
}); Example here - click on the link (2), then click on the Notice that the link (2) and link (3) are 'exact' same routes. But they both don't get the However the That is because of the trailing slash |
Quote from Evan in #608
So you need to just explicitly put names on default children. @HashemQolami It seems like a bug, would you like to open a new issue? Thanks! |
@fnlctrl For sure! Thanks. |
Sorry, but this explanation doesn't make sense to me
Why call it a default child if it's not going to render by default unless I'm explicitly telling it to? Isn't that what I'm doing by configuring it as the default in the first place? I'm having a hard time accepting this "expected" behavior. |
Completely agree with @joemsak . Just seems like counter-intuitive routing behaviour. If I point a route to a component, and I have a child route with no parameters, this child route should automatically be triggered when the parent route is called without parameters, but it's not. It have to explicitly tell the router: "Render this child component". Why use a router in a first place when it does not route. Edit: Consider the following code. This does NOT work: const routes: Array<RouteRecordRaw> = [
{
path: "/",
redirect: { name: "Books" },
},
{
path: "/books",
component: Books,
name: "Books",
children: [
{
path: "",
name: "BookList",
component: BookList,
}, this would work: const routes: Array<RouteRecordRaw> = [
{
path: "/",
redirect: "/books",
},
{
path: "/books",
component: Books,
children: [
{
path: "",
name: "BookList",
component: BookList,
}, I have no idea why named routes behave differently in this case. Cannot wrap my head around it. |
It's easy to make it work with name routes. const routes: Array<RouteRecordRaw> = [
{
path: "/",
redirect: { name: "Books" },
},
{
path: "/books",
component: Books,
name: "Books",
redirect: { name: "BookList" },
children: [
{
path: "",
name: "BookList",
component: BookList,
}, |
I think that using 'redirect' to go to default children is an inappropriate naming. It's unnatural. |
Hello !
found another bug related to children routes and empty paths.
On this jsFiddle:
https://jsfiddle.net/p7uk1pbv/6/
click the 3 links in the jsfiddle one after another in the order: 1, 2, 3
note that (1) and (3) are 'exact' same routes but they don't render the same children components
you have to click (2) between (1) and (3) in order to make the bug reproducible
The text was updated successfully, but these errors were encountered: