Last active
March 10, 2021 13:09
-
-
Save silkentrance/9caa45481329f6ef911bd5eae5dbb7c3 to your computer and use it in GitHub Desktop.
vue-router typescript integration fails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue from 'vue'; | |
import Component from 'vue-class-component'; | |
@Component({ | |
name : 'component' | |
}) | |
export default class MyComponent extends Vue { | |
beforeCreate() { | |
console.log('entering Bootstrap#beforeCreate'); | |
} | |
created() { | |
console.log('entering Bootstrap#created'); | |
} | |
activated() { | |
console.log('entering Bootstrap#activated'); | |
} | |
beforeRouteEnter(to, from, next) { | |
console.log('entering Bootstrap#beforeRouteEnter'); | |
next(); | |
} | |
beforeRouteUpdate(to, from, next) { | |
console.log('entering Bootstrap#beforeRouteUpdate'); | |
next(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div>Guards are never called...</div> | |
</template> | |
<script lang="ts"> | |
import MyComponent from './MyComponent'; | |
export default MyComponent; | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Component from 'vue-class-component' | |
// Register the router hooks with their names | |
Component.registerHooks([ | |
'beforeRouteEnter', | |
'beforeRouteLeave', | |
'beforeRouteUpdate' // for vue-router 2.2+ | |
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue from 'vue'; | |
import VueRouter from 'vue-router'; | |
import Component from 'vue-class-component' | |
import './register-hooks' | |
import MyComponent from './MyComponent.vue'; | |
Vue.use(VueRouter) | |
export default new VueRouter({ | |
mode : 'history', | |
routes : [ | |
{ path: '/', component: MyComponent, meta : { title: 'Default Wiki Page'}}, | |
] | |
}); |
No, I just made use of the ability to separate the code from the actual template.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi!, I have the same problem, but Is it required to have the component (MyComponent.ts) in another file?, and then import in "MyComponent.vue" file? I could not make it work.