Vue-Router去除路由的#号
Vue-Router去除路由的#号开启HTML5 History 模式src => router => index.jsimport Vue from "vue";import VueRouter from "vue-router";import Home from "../views/Home.vue";Vue.use(VueRouter);const routes = [{path
·
Vue-Router去除路由的#号
开启HTML5 History 模式
src => router => index.js
import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
Vue.use(VueRouter);
const routes = [
{
path: "/",
name: "Home",
component: Home,
},
{
path: "/about",
name: "About",
component: () =>
import(/* webpackChunkName: "about" */ "../views/About.vue")
}
];
const router = new VueRouter({
// History 模式
mode: 'history',
routes
});
export default router;
更新
2020.10 最新版本的解决办法
import {createRouter, createWebHistory} from 'vue-router';
import Home from '../views/Home.vue';
import About from '../views/About';
const routes = [
{
path: '/',
name: 'Home',
component: Home,
},
{
path: '/about',
name: 'About',
component: About,
},
];
const router = createRouter({
history: createWebHistory(),
routes,
});
export default router;
把第一行默认引入的 createWebHashHistory
换成 createWebHistory
然后修改下面的对应方法即可。
欢迎关注微信公众号"程序员小辉"
更多推荐
已为社区贡献2条内容
所有评论(0)