Vue Router enables history mode (go to #) to step on the pit record

My correct code

Routing version: ^4.0.0-0
Maybe my routing version is relatively high. After looking for a long time online modification plan, it is all wrong , including the official routing website.
Then I rebuilt a project. When I built the project, I directly checked the history mode. After I created it, I found out that it looks like this:

import {
    
    createRouter, createWebHistory} from 'vue-router'
import Home from '../components/home.vue'
import Index from '../components/Logged/index.vue'
import Login from '../components/login.vue'

const routes = [(略)]

const router = createRouter({
    
    
    history: createWebHistory(process.env.BASE_URL),
    routes
})

export default router

Note that at the end, it is not mode, but history.

Here are my dependencies:

"dependencies": {
    
    
    "core-js": "^3.6.5",
    "element-plus": "^1.0.2-beta.35",
    "element-ui": "^2.15.1",
    "vue": "^3.0.0",
    "vue-router": "^4.0.0-0",
    "vuex": "^3.6.2"
  }

One version is different from the other. If it doesn’t work, you can try the following two

Written on the official website

Address: https://router.vuejs.org/zh/guide/essentials/history-mode.html The
following is written on the official website:

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

This didn't work for a long time.

Another version

This version changed the first line of createWebHashHistory to createWebHistory and changed the mode of the router. I tried it but it didn’t work. . . (as follows)

import {
    
    createRouter, createWebHistory} from 'vue-router'

(略)

const router = new VueRouter({
    
    
  mode: createWebHistory(),
  routes
})

Guess you like

Origin blog.csdn.net/weixin_43529394/article/details/115018179