Vue.js 路由到localhost:8081/home不工作但localhost:8081/#/home工作
我知道这是一个非常基本的问题,但我仍然无法理解这个非常简单的问题。给你 使用vuejs路由器,我尝试路由到Custom.vue页面 自定义.vueVue.js 路由到localhost:8081/home不工作但localhost:8081/#/home工作,vue.js,vue-router,Vue.js,Vue Router,我知道这是一个非常基本的问题,但我仍然无法理解这个非常简单的问题。给你 使用vuejs路由器,我尝试路由到Custom.vue页面 自定义.vue <template> <div> <h1>Hello User</h1> </div> </template> <script> export default { name: 'Custom' } </script> 问题:现在这里发生
<template>
<div>
<h1>Hello User</h1>
</div>
</template>
<script>
export default {
name: 'Custom'
}
</script>
问题:现在这里发生的痛苦的事情是,当我尝试使用
localhost:8081/#/home
访问页面时,页面加载正确,但使用localhost:8081/home
则不正确。这是因为您没有启用历史模式,您可以通过类似的方式启用历史模式
new Router({
mode: 'history',
routes,
base: process.env.BASE_URL
})
您需要启用历史记录模式并设置基本服务器入口点:非常感谢!
new Router({
mode: 'history',
routes,
base: process.env.BASE_URL
})