Vue 去除hash路由默认的#
场景. vue 开启路由后,默认的路由中会带上'#', 不雅解决. 实例化路由规则的时候const router = new VueRouter({mode: ‘history’,history: true,routes // (缩写)相当于 routes: routes})...
·
场景
. vue 开启路由后,默认的路由中会带上'#', 不雅
分析
. vue路由默认的是hash的模式, 开启history默认 可以向正常的路由访问
但是这种需要后端支持, 不然很容易404
解决
1. 实例化路由规则的时候
const router = new VueRouter({
mode: ‘history’,
routes // (缩写)相当于 routes: routes
})
2. nginx 相应的配置
location / {
try_files uriuri<script type="math/tex" id="MathJax-Element-1">uri </script>uri/ /index.html;
}
3. 参考文档 `https://router.vuejs.org/zh/guide/essentials/history-mode.html#%E5%90%8E%E7%AB%AF%E9%85%8D%E7%BD%AE%E4%BE%8B%E5%AD%90`
更多推荐
所有评论(0)