首页 > 编程 > JavaScript > 正文

Vue 去除路径中的#号

2019-11-19 13:59:53
字体:
来源:转载
供稿:网友

在开发过程中发现路径中带有/#/的标示,而且还去不掉,很丑陋。

众所周知,vue-router有两种模式,hash模式和history模式。

带#的则是hash模式。

将router中的mode设置为history就可以了

接下来有个问题,界面一刷新,就变404了!!!!

网上搜了下,需要对后端环境进行一个配置。

这里只列举nginx的配置,其他的配置点击这里去官网看

先配置config/index.js

修改assetsPublicPath为根目录

module.exports = {  build: {      env: require('./prod.env'),      index: path.resolve(__dirname, '../dist/index.html'),      assetsRoot: path.resolve(__dirname, '../dist'),      assetsSubDirectory: 'static',      assetsPublicPath: '/',   // hash 模式会默认的在此处 添加为 assetsPublicPath: './'      productionSourceMap: true,      ...    }}

然后配置nignx

server {    listen 0.0.0.0:12345;    location / {        root /home/我的应用跟目录;        try_files $uri $uri/ /index.html =404;  // 这个是重点    }    error_page 404 /index.html}

Url再也没有#了,多完美

总结

以上所述是小编给大家介绍的Vue 去除路径中的#号,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对武林网网站的支持!

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表