-
Notifications
You must be signed in to change notification settings - Fork 433
observe router lifecycle hooks #38
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
Comments
IMHO, FYI, you can achieve this by creating a custom decorator. import { createDecorator } from 'vue-class-component'
const Hook = createDecorator((options, key) => {
options[key] = options.methods[key]
delete options.methods[key]
})
// ---------
@Component
class MyComp extends Vue {
@Hook
beforeRouteEnter () {
// ...
}
} |
I have copied your code into a third module,vue-router-decorator. import {RouterHook, Router} from 'vue-router-decorator';
@Component({
name: 'XXComponent'
})
export default class XX extends Vue implements Router{
@RouterHook
beforeRouteEnter(to, from, next) {
next();
}
@RouterHook
beforeRouteLeave(to, from, next) {
next();
}
} |
I agree with @ktsn that the library should not be bound to to other libs. But, maybe this then calls for the ability to extend it - the same way that Vue.use(VueRouter) adds the hooks to the lifecycle of a component, Component.use(VueRouter) could extend it with the hooks? that way, the component is gaining the same extensions as the vanilla vue object |
@tonypee Released the extending hooks feature as v4.4.0 :) |
that looks perfect! great work |
Hook is not called when Component is extending class and its defined in extended class, this is feature ? |
It would be nice to observe beforeRouteEnter and beforeRouteLeave as lifecycle hooks. Should they be added to the internal hooks list?
They seem as common, if not more common than some of the other hooks, especially for confirming page exit
The text was updated successfully, but these errors were encountered: