admin管理员组文章数量:1430125
This has been puzzling me for a while. I have searched quite a bit, but still have no idea, why the route-hooks doesn’t work in ponent:
1. The ponent is loaded from RouterView:
<router-view class="z1" :key="$route.name" />
2. I have registered the hooks in main.ts
, and also in My.vue
-- BEFORE the class definition (to ensure the registration is right here):
Component.registerHooks([
'beforeRouteEnter',
'beforeRouteLeave',
'beforeRouteUpdate',
]);
3. The hook even works in my router config:
{
path: '/my',
name: 'my',
ponent: My,
// beforeEnter: (to: Route, from: Route, next: any): void => {
// console.log('It works!’); // It works here!
// }
},
4. But it doesn’t work in my Component:
@Comp()
export default class My extends Vue {
public beforeRouteEnter (to: Route, from: Route, next: any): void {
debugger; // not triggered!
next((vm: Vue.Component) => {
debugger; // not triggered!
next();
});
}
}
So could anyone help me with that?
This has been puzzling me for a while. I have searched quite a bit, but still have no idea, why the route-hooks doesn’t work in ponent:
1. The ponent is loaded from RouterView:
<router-view class="z1" :key="$route.name" />
2. I have registered the hooks in main.ts
, and also in My.vue
-- BEFORE the class definition (to ensure the registration is right here):
Component.registerHooks([
'beforeRouteEnter',
'beforeRouteLeave',
'beforeRouteUpdate',
]);
3. The hook even works in my router config:
{
path: '/my',
name: 'my',
ponent: My,
// beforeEnter: (to: Route, from: Route, next: any): void => {
// console.log('It works!’); // It works here!
// }
},
4. But it doesn’t work in my Component:
@Comp()
export default class My extends Vue {
public beforeRouteEnter (to: Route, from: Route, next: any): void {
debugger; // not triggered!
next((vm: Vue.Component) => {
debugger; // not triggered!
next();
});
}
}
So could anyone help me with that?
Share Improve this question edited Jul 30, 2019 at 15:21 shuangwhywhy asked Jul 5, 2019 at 10:57 shuangwhywhyshuangwhywhy 5,6252 gold badges21 silver badges30 bronze badges1 Answer
Reset to default 7should be working:
@Comp({
beforeRouteEnter (
to: Route,
from: Route,
next: (to?: RawLocation | false | ((vm: V) => any) | void) => void
): void {
next(vm => {});
}
})
export default class My extends Vue {}
本文标签: javascriptVue Router hooks not triggered in componentusing TypescriptStack Overflow
版权声明:本文标题:javascript - Vue Router hooks not triggered in component, using Typescript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745545361a2662678.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论