2

I have a index.js file inside router folder and here is the code, but the register component is not showing in /register route. Only the HelloWorld component is shown in all the routes.

import Vue from 'vue' import Router from 'vue-router' import HelloWorld from '@/components/HelloWorld' import Register from '@/components/Register' Vue.use(Router) export default new Router({ routes: [ { path: '/', name: 'HelloWorld', component: HelloWorld }, { path:'/register', name:'Register', component:Register } ] }) 
1

2 Answers 2

3

You should set mode of router history, because default is hash router, it is not fire while history changes.

import Vue from 'vue' import Router from 'vue-router' import HelloWorld from '@/components/HelloWorld' import Register from '@/components/Register' Vue.use(Router) export default new Router({ mode: 'history', routes: [ { path: '/', name: 'HelloWorld', component: HelloWorld }, { path:'/register', name:'Register', component:Register } ] }) 
Sign up to request clarification or add additional context in comments.

Comments

2

You should set history mode.

Cheers!!

1 Comment

Please add some explanation to your answer: why should one do so, and how?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.