0

I'm using Vue 3 and Vue Router. My app is working with createWebHashHistory, but when I change to mode: 'history' the pages don't load.

const router = createRouter({
  mode: 'history',
  routes
})

I know that in production I have to configure the server to use mode: 'history', but I'm serving the app in a development server using npm run serve.

4 Answers 4

2

If this problem occurs, it may be a configuration problem. Check if the publicPath in vue.config.js or config/index.js is / instead of ./

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

Comments

0

mode: 'history': does not directly access the project in the production environment, need nginx forwarding,You can use CreateWebhashhistory

Comments

0

This is a Breaking Changes.

The mode: 'history' option has been replaced with a more flexible one named history. Depending on which mode you were using, you will have to replace it with the appropriate function:

  • "history": createWebHistory()
  • "hash": createWebHashHistory()
  • "abstract": createMemoryHistory()

Therefore, you need to update your code to the new way:

createRouter({
  // mode: 'history',
  history: createWebHistory(),
  routes: [],
})

The createRouter receives an options of type RouterOptions, it has no mode attribute.

So, mode: 'history' is not work anymore.

You can see more here(new history option to replace mode)

1 Comment

createWebHistory() isn't working either, only createWebHashHistory()
0

https://webpack.js.org/configuration/dev-server/#devserverhistoryapifallback It works for me, in vue.config.js

devServer: { historyApiFallback: true, },

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

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.