0

我试图在我的 VueJS webapp 的 URL 中删除 #,但即使使用

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

#依然出现。我很确定这是由于 createWebHashHistory 函数造成的,但我无法删除它,否则 UI 不会显示。

所以我尝试了另一件事:

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

但 ui 甚至不在这里显示。

Vue.JS 的官方文档在这一点上对我没有帮助,有人可以帮我吗?

4

2 回答 2

1

这对我有用:

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

所以它要么是history: createWebHashHistory(),要么createRouter

于 2021-02-18T11:59:11.507 回答
0

这是我的 index.js

import { createRouter, createWebHistory } from "vue-router";
import Home from "../views/Home.vue";
import About from "../views/About.vue";

const routes = [
  {
    path: "/",
    name: "Home",
    component: Home,
  },
  {
    path: "/about",
    name: "About",
    component: About,
  },
];

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

export default router;

于 2021-07-12T03:06:08.340 回答