【问题标题】:Routing to localhost:8081/home not working but localhost:8081/#/home working路由到 localhost:8081/home 不工作,但 localhost:8081/#/home 工作
【发布时间】:2019-08-30 06:07:25
【问题描述】:

我知道这是一个非常基本的问题,但我仍然无法理解这个非常简单的问题。在这里。

使用 vuejs-router,我尝试路由到页面 Custom.vue。

自定义.vue

<template>
<div>
   <h1>Hello User</h1>
 </div>
</template>

<script>
export default {
    name: 'Custom'
}
</script>

在 routes 变量中,我配置了如下路径。

const routes = [
  { path: '/', component: HelloWorld },
  { path: '/home', component: Custom },
]

问题:现在发生的痛苦事情是,当我尝试使用 localhost:8081/#/home 访问页面时,页面加载正确,但使用 localhost:8081/home 时却没有。

【问题讨论】:

标签: vue.js vue-router


【解决方案1】:

这是因为你没有开启历史模式,你可以通过类似这样的方式开启历史模式

new Router({
  mode: 'history',
  routes,
  base: process.env.BASE_URL
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-24
    • 2020-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-22
    • 1970-01-01
    相关资源
    最近更新 更多