Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't get the right route path in 'ready' method #75

Closed
dazhenhan opened this issue Aug 14, 2015 · 1 comment
Closed

can't get the right route path in 'ready' method #75

dazhenhan opened this issue Aug 14, 2015 · 1 comment

Comments

@dazhenhan
Copy link

Simplify my scene:

I wrote two components, a login.vue and a main.vue, after click a button in login.vue ,it executes 'route.go('/main')', the router-view renderered the main.vue content, but, in the main.vue's ready method, 'router.app.$route.path' returns '/login', not '/main', I don't know other ways to get the right route path in 'ready' method after a router-view is changed

I use vue-router 0.4.0, and vue.js 0.12.10

is there a proper way to get the right path after change a route?

before I got the problem above, I use 'route.afterEach' method to capture the route change event, it's seems that this method is removed in vue-router 0.4.0

I find a way, use 'router._currentRoute.path' can read the right path in 'ready' method, but, I think it's not a good way

@dazhenhan
Copy link
Author

sorry, I don't read the new example completely, I saw the new 'route' attribute in vue component

but, look, I put a router-view label in main.vue, after I changed the menu item in main.vue, the main.vue's router-view's content changed, then main.vue's life-cycle methods are invoked again

I solve the problem, the code like below:

module.exports = {
    route: {
        function(transition){
            this.path = transition.to.path
        }
    },
    data: {
        path: '',
        menus: ['a', 'b', 'c']
    },
    ready: function(){// this method will be invoked every time after the router-view is re-renderered
        dosth(this.path)
    }
}

is it a proper way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant