Vue-router: Warn when navigating to named route with a default child (through alias instead of path)

Created on 18 Oct 2017  路  1Comment  路  Source: vuejs/vue-router

Version

3.0.1

Reproduction link

http://jsfiddle.net/w6q9uyro/

Steps to reproduce

Run this link: http://jsfiddle.net/w6q9uyro/
Try route to /home

What is expected?

It should load component Home and run HomeFirstChild component because children route alias is empty ('' default route).

What is actually happening?

It only load Home component and nothing more.


This problem is shown in version 2.8.x 3.0.x.

In version 2.7.0 work in first time route but if we want route more than one the router doesn't want work properly

version 3.0.1: http://jsfiddle.net/w6q9uyro/

version 2.7.0: http://jsfiddle.net/mx3a6vLj/

Workaround

Add redirect in parent route:
http://jsfiddle.net/zy0db0wx/

fixed on 4.x improvement

Most helpful comment

I think this is actually expected behaviour. You see, when you navigate to a route by name, vue-router will not render this route's default child (a child with path: ''). To do that, you have to navigate to that default child route by name. (As you also do with {name: 'home.first-child'} in the example.

Normally, you see a warning about this in the development/non-minified builds defined here:

`Named Route '${route.name}' has a default child route. ` +
 `When navigating to this named route (:to="{name: '${route.name}'"), ` +
 `the default child route will not be rendered. Remove the name from ` +
 `this route and use the name of the default child route for named ` +
 `links instead.`

The problem is that you don't get this warning, presumably because you defined the default path through through alias, not the path.

We should check how to improve this situation that the warning also appears for aliases.

>All comments

I think this is actually expected behaviour. You see, when you navigate to a route by name, vue-router will not render this route's default child (a child with path: ''). To do that, you have to navigate to that default child route by name. (As you also do with {name: 'home.first-child'} in the example.

Normally, you see a warning about this in the development/non-minified builds defined here:

`Named Route '${route.name}' has a default child route. ` +
 `When navigating to this named route (:to="{name: '${route.name}'"), ` +
 `the default child route will not be rendered. Remove the name from ` +
 `this route and use the name of the default child route for named ` +
 `links instead.`

The problem is that you don't get this warning, presumably because you defined the default path through through alias, not the path.

We should check how to improve this situation that the warning also appears for aliases.

Was this page helpful?
0 / 5 - 0 ratings