Vue 去除路由路径中的#

77 阅读1分钟

问题

访问路径的时候,会出现#,想去除

image.png

import  { createRouter, createWebHashHistory } from "vue-router"
import Auth from "../views/Auth.vue"


// 定义路由
const routers = [{
    path:"/",
    redirect:"/auth"
},{
    path:"/auth",
    name:"auth",
    component:Auth
}]

// 创建router实例
const router = createRouter({
    history:createWebHashHistory(),
    routes:routers
})

// 导出router实例
export default router


解决策略

image.png

image.png

import  { createRouter, createWebHistory  } from "vue-router"
import Auth from "../views/Auth.vue"


// 定义路由
const routers = [{
    path:"/",
    redirect:"/auth"
},{
    path:"/auth",
    name:"auth",
    component:Auth
}]

// 创建router实例
const router = createRouter({
    history:createWebHistory (),
    routes:routers
})

// 导出router实例
export default router