R
R
Roman Rakzin2016-09-28 13:23:35
Vue.js
Roman Rakzin, 2016-09-28 13:23:35

How to catch the transition to another route event in vue.js?

There is a router

router.map({
        '/': {
            component: Index
        },
        '/user/:id': {
            component: UserInfo,
            name: 'UserInfo.show'
        },
    ...
    });


I need that if you follow the link '/' - function 1 worked, if the link - '/user/:id', then function 2 worked. And when refreshing the page, if the route is on the link '/user/:id', what would function 2 work in the same way.
How to do this?
(I read about router.beforeEach(function(transition), but it works, with every transition and I don’t understand how to figure it out. In angular, the controller just worked, but I didn’t find it anywhere.)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question