2

I initialized a project with the vue-cli,and I just configured the router. why is always open the 'HelloWorld' component when I try to enter: 'http://localhost:8080/HelloWorld2' or 'http://localhost:8080/HelloWorld1'.

import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import HelloWorld1 from '@/components/HelloWorld1'
import HelloWorld2 from '@/components/HelloWorld2'
import HelloWorld3 from '@/components/HelloWorld3'

Vue.use(Router)

export default new Router({
    routes: [
       {
           path: '/',
           name: 'HelloWorld',
           component: HelloWorld
       },
       {
           path: '/HelloWorld1',
           component: HelloWorld1,
           // childres:[
           //     {
           //         path: 'HelloWorld3',
           //         component: HelloWorld3,
           //     },
           // ]
       },
       {
           path: '/HelloWorld2',
           component: HelloWorld2
       }
   ]

})

1 Answer 1

1

The vue-router uses hash mode by default. In your configuration, you probably want to use html5 history mode. See https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations for reference.

This can be changed in your Router setup:

const router = new VueRouter({ mode: 'history', routes: [...] })

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.