Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue url changes on navigation

I am just getting started with Vue. I installed @Vue/Cli (that's version 3) and also cli-init so I can use version 2's commands. To create my project I used vue init webpack . While running the app on the browser I noticed strange behaviour; my routes are being changed!

Initial Route "localhost:8080/"

Navigating to the route url changes to "localhost:8080/#/"

Also with another route "localhost:8080/about"

Navigating to this route the url changes to "localhost:8080/about#/"

I don't understand what is going on. It renders the components though, but the url just changes. Here is my routes config:

export default new Router({
  routes: [
    {
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld,
    },
    {
      path: '/about',
      name: 'AboutComponent',
      component: AboutComponent,
    },
    {
      path: '*',
      name: '404',
      component: HelloWorld,
    },
  ],
});

No router links, I navigated by typing the paths. My router setting is default.

like image 900
LeanKhan Avatar asked Jun 03 '26 15:06

LeanKhan


1 Answers

You can probably answer the question yourself by reading vue-router documentation here (https://router.vuejs.org/guide/essentials/history-mode.html)

By default vue-router works in hash mode. Routes are changed in the browser with a 'hash' for compatibility with old browsers. Nowadays you can safely use history mode, and your URLs won't change in the browser location box.

However, I recommend that you read and fully understand how client-side routing works and what's the required server-side configuration you need to make your app work properly.

Welcome to Vue.JS!

like image 194
tato Avatar answered Jun 06 '26 07:06

tato



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!