Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue webpack is adding #/ to all URLs

I am following along with some Vue projects using vue init webpack test, but it seems like when running npm run dev, there is always a #/ appended to all urls.

This is also true for when I create a new component and route to it. If i do something like http://localhost:8080/newpath, it becomes http://localhost:8080/newpath#/.

Is there a config variable I can set so that the #/ is not appended to every URL? Using regex to remove it on every URL seems really unwieldily.

I am not including any actual source code because this is from the HelloWorld app that vue init creates.

I am using the latest versions for vue cli 3.

like image 247
securisec Avatar asked Feb 25 '19 17:02

securisec


People also ask

Does Vue have webpack?

Simple Configuration Some webpack options are set based on values in vue. config. js and should not be mutated directly.

Does Vue use webpack by default?

vue extension, we use a default app entry to load the given component, otherwise we treat it as a normal webpack entry.


1 Answers

From the docs on HTML5 History Mode:

The default mode for vue-router is hash mode - it uses the URL hash to simulate a full URL so that the page won't be reloaded when the URL changes.

So you need to change your Vue router to use the HTML5 history mode:

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

Please also continue reading the docs beyond that because you will need to adjust your actual server configuration to support this mode so that users will be sent to the appropriate location if they copy and paste the address bar URL to a new tab.

like image 154
zero298 Avatar answered Oct 11 '22 23:10

zero298