vue-router 4.0.0-alpha.6及以上版本的写法更新了
上代码
自己配置的index.js
hash模式可以让前端来代理url,如果改为history模式,那便是直接映射的地址。
改为history模式之后如果出现空白页面的情况,首先检查有无报错,无报错的情况下就是地址没有映射到vue-router。要保持router的地址和地址栏的地址是一致的,才不会导致空白页。
import { createRouter,createWebHistory} from "vue-router";
import routes from './routes' //引入路由配置文件
const router = createRouter({
history: createWebHistory(), //history模式 这个模式就是去掉#号
//history:createWebHashHistory() //hash模式
routes,
});
export default router;