Answer the question
In order to leave comments, you need to log in
Why doesn't $router.addRoutes work?
The situation is this, when initializing the route object, there are three route objects:
var routes = [
{ name: 'a', path: '/', component: Start },
{ name: 'b', path: '/signup', component: SignUp, alias: '/sign' }
{ name: 'd', path: '*', component: NotFound }
]
this.$router.addRoutes([{ name: 'c', path: '/user', component: User }]);
Vue.use(Router)
var routes = [
{ name: 'a', path: '/', component: Start },
{ name: 'b', path: '/signup', component: SignUp, alias: '/sign' },
{ name: 'd', path: '*', component: NotFound }
]
var router = new Router({
mode: 'history',
routes: routes
})
export default {
name: 'app',
router: router,
data: function() {
return {
message: 'Hello'
}
},
methods: {
addNewUrl: function(mes) {
this.$router.addRoutes([{ name: 'c', path: '/user', component: User }]);
console.log(this.$router); // получаю все те же самые три маршрута 'a', 'b', 'd'
},
this.$router.addRoutes([{ name: 'c', path: '/user', component: User }]);
this.$router.push('/user');
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question