Vue-router: vue2 router state change router.addRoutes

Created on 15 Apr 2017  Â·  7Comments  Â·  Source: vuejs/vue-router

Version

2.2.0

Reproduction link

https://github.com/myxingke/vueManage.git

Steps to reproduce

Not landed router Array
[{xxxx}, {xxxx}, {xxxx},{'path': '*'}]
notice {'path':‘*’}

login code
let routes = sessionRoutes(res.data.menu) for( let [ index, route ] of new Map( routes.map( ( item, i ) => [ i, item ] ) ) ) { let key = this.$router.options.routes.length-1 this.$router.options.routes.splice(key, 0, route) } this.$router.addRoutes(routes)
result router Array
[{xxxx}, {xxxx}, {xxxx},{new router},{new router},{'path': '*'}]

What is actually happening?
But that's it
[{xxxx}, {xxxx}, {xxxx},{'path': '*'},{new router},{new router}]
notice ,{'path': '*'}

When I click on the new page, it appears behind {'path': '*'}. This is not the result I want。I hope one is one

I Hope

It is it [{xxxx}, {xxxx}, {xxxx},{new router},{new router},{'path': '*'}]
Not it [{xxxx}, {xxxx}, {xxxx},{'path': '*'},{new router},{new router}]

What is expected?

[{xxxx}, {xxxx}, {xxxx},{new router},{new router},{'path': '*'}]

What is actually happening?

But that's it
[{xxxx}, {xxxx}, {xxxx},{'path': '*'},{new router},{new router}]


Not landed router Array
[{xxxx}, {xxxx}, {xxxx},{'path': '*'}]
notice {'path':‘*’}

login code
let routes = sessionRoutes(res.data.menu) for( let [ index, route ] of new Map( routes.map( ( item, i ) => [ i, item ] ) ) ) { let key = this.$router.options.routes.length-1 this.$router.options.routes.splice(key, 0, route) } this.$router.addRoutes(routes)
result router Array
[{xxxx}, {xxxx}, {xxxx},{new router},{new router},{'path': '*'}]

What is actually happening?
But that's it
[{xxxx}, {xxxx}, {xxxx},{'path': '*'},{new router},{new router}]
notice ,{'path': '*'}

When I click on the new page, it appears behind {'path': '*'}. This is not the result I want。I hope one is one

I Hope

It is it [{xxxx}, {xxxx}, {xxxx},{new router},{new router},{'path': '*'}]
Not it [{xxxx}, {xxxx}, {xxxx},{'path': '*'},{new router},{new router}]

Or else is the meaning of dynamic routing?

Most helpful comment

@LinusBorg I think I say it in Chinese:太J2感谢你了。

All 7 comments

This was fixed with this commit:

https://github.com/vuejs/vue-router/commit/0fed2005c05b8706842a6d5249738fa081c8ba25

The fix will be in the next release

@LinusBorg Really? What's the next version?

The one that is not released yet.

@LinusBorg I think I say it in Chinese:太J2感谢你了。

@LinusBorg I want to add addRoutes appendRoutes replaceRoutes deleteRoutes

replaceRoutes deleteRoutes
that would be a new feature request.

@LinusBorg I anticipate. hei hei hei

Was this page helpful?
0 / 5 - 0 ratings