当我使用 vue-router 与 express 一起使用时,我的 url 中的'#'不正确



url显示为

localhost:3000/索引#/dashboard

但不是

localhost:3000/ index/#/dashboard

这是有线的。

这是我的明确代码。

app.get('/index', function (req, res) {
    const html = fs.readFileSync('index.html', 'utf-8');
    res.send(html);
});

和我的vue-router代码。

{
  name: 'dashboard',
  path: '/dashboard',
  component: require('../views/dashboard.vue')
}

尝试在Vuerouter中设置mode: 'history'

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

有关Express的更多信息,请参阅VUE路由器HTML5历史记录MDOE

最新更新