Setting up in-Component Hooks
Finally, we can also use in-component Hooks as component life cycle Hooks where we want to scope those Hooks to component-level for better code maintenance or enhance the workflow where the same component needs to behave differently in a certain use case.
We can have the About
component now with the beforeRouteEnter()
Hook defined as follows:
<script> export default { Â Â data() { Â Â Â Â return { Â Â Â Â Â Â user: '' Â Â Â Â } Â Â }, Â Â beforeRouteEnter(to, from, next) { Â Â Â Â if (!to.params || !to.params.user) { Â Â Â Â Â Â next(comp => { Â Â Â Â Â Â Â Â comp.user = 'Alex' Â Â Â Â Â Â }) Â Â Â Â } Â Â Â Â else { Â Â Â Â Â Â next(); Â Â Â Â } Â Â } } </script...