vue-router 4.0 取消了 addRouters 设置动态路由只能使用 addRouter
动态路由一般是从后端获取 然后经过数据格式处理
但在页面刷新后会出现一下警告:
vue-router.esm-bundler.js6c02:71 [Vue Router warn]: No match found for location with path “/formlist/stepform/other”
但通过getRouters
又能够获取到所有的异步路由
分析:页面刷新后由于是异步获取的原因 在next() 函数放行之后才获取到
此时就要使用next({ ...to, replace: true })
来确保addRoute()
时动态添加的路由已经被完全加载上去。
next({ ...to, replace: true })
中的replace: true
只是一个设置信息,告诉VUE本次操作后,不能通过浏览器后退按钮,返回前一个路由。
因此next({ ...to, replace: true })
可以写成