I have a basic rule to redirect my home page to resumes page.
my rule :
...
ready: function() {
if(this.isLoggedIn){
this.router.go("/resumes");
}
},
...
my route map :
module.exports = {
'/': {
component: require('./views/home')
},
'/auth/login': {
component: require('./views/auth/login')
},
'/auth/register': {
component: require('./views/auth/register')
},
'/resumes': {
component: require('./views/resumes')
},
// 404 NotFound
'*': {
component: {
template: "not found"
}
}
};
But when I login, router changes url on browser but still show home page. It does not redirect me to /resumes page?
what is wrong?
there is no vm.router. There is vm.$route. So you can do this.$route._router.go('/resumes').
Ouch :) Thank you @azamat-sharapov . now, It works perfectly thanks of you.
Edit :
It works for a few times but I gives same problem again but in a different way.
It loads pages two times. firstly loads home page after that loads resumes page.
-Home Page
-Footer
-Header
-Resumes Page
-Footer

@yyx990803 I could not found any solution about the problem. It still calls home page and resumes pahe both. What is wrong?
@kamuran21 I advice you to ask such questions in vuejs/Discussion repo. More important thing - you need to provide reproduction for your issue (jsfiddle, codepen, etc.). Take this as example: http://jsfiddle.net/yyx990803/xyu276sa/
BTW, on latest version, this.$route._router was changed to vm.$route.router, just so you are aware.
@azamat-sharapov thank you. When I use v-link directive, it works perfectly. But the same problem still exist. router.go calls both of page. I will check it for latest version.
I think this property vm.$route.router should definitely be mentioned somewhere in the documentation :)
@Flo-Schield-Bobby Yes I agree. Can someone see whatever is proper, and add an example in the documentation?
@alteredstudio it is already included: http://router.vuejs.org/en/route.html
Also starting in 0.7.9 you can directly access this.$router in any child component of a router app.
when I use this.$router.go('/dashboard') it reloads my page over and over again, it does not go to the destination.
What am I doing wrong?
@dudesweet100 In 2.0 it's renamed to $router.push, and $router.go is an alias of window.location.gowindow.history.go
@fnlctrl window.location.go is native? I couldn't find it on location object when any web app runs.
@kamuran21 😅 Oops, was a typo, should be window.history.go.
Why is this stuff not in the docs??? It would make sense that a lot of people would be navigating this way from a component.
@fnlctrl I know the page exists. But I am talking about adding an example from inside a component. Such as this.$router.go('/') . I have had many a folk from my company get confused about how to access the router inside of a component.
omg it took me 2 hours to figure out that router.go was the equivalent of window.history.go, thank's to @fnlctrl ... Weird we couldn't find it faster :p but thank's anyway !
Most helpful comment
@dudesweet100 In 2.0 it's renamed to
$router.push, and$router.gois an alias ofwindow.location.gowindow.history.go