【问题标题】:How to remove # from vuejs root router? [duplicate]如何从 vuejs 根路由器中删除#? [复制]
【发布时间】:2020-07-23 09:26:25
【问题描述】:

当我去http://localhost:8080/ 它重定向到http://localhost:8080/#/

为什么要加“#”?

import Vue from 'vue'
import App from './App.vue'    
import VueRouter from 'vue-router'
import List from './components/list'
import PostForm from './components/postform'

Vue.config.productionTip = false
Vue.use(VueRouter)             

const routes = [               
  { path: '/', component: List, name: 'root' },
  { path: '/posts/new', component: PostForm }
]     

const router = new VueRouter({ 
  routes
})  

new Vue({
  router,
  render: h => h(App),         
}).$mount('#app')

【问题讨论】:

标签: vue.js vue-router


【解决方案1】:

默认情况下 VueRouter 使用hash mode

您可以根据需要将模式更改为history

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

这样做的主要原因可能是,如果您使用history 模式,您需要为您的网络服务器进行特殊设置才能正确处理网址。使用 hash bangs 时,它开箱即用。

【讨论】:

    猜你喜欢
    • 2011-09-16
    • 1970-01-01
    • 2020-10-05
    • 2021-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多