I'm reviewing Vue and it's router component, although I'm having some issues getting the router component to work. Error in console below:
Uncaught ReferenceError: router is not defined
Hi all,
I'm importing the Vue and VueRouter into an index.html and trying my best to read the documentation to get the router initialized, but cannot seem to it working.
In index.html:
<script type="module" src="/assets/js/main.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
In main.js:
import VueRouter from 'vue-router'
Vue.use(VueRouter)
var router = new VueRouter({
routes: [
{ path: 'home', component: home }
]
});
var app = new Vue({
router,
el: '#app',
data: {
...etc
Help would be appreciated...
Many thanks.
main.jsthen I would suggest reordering your<script>tags to putmain.jslast. Otherwise, could you include the full stacktrace for the error?