您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

路径中#号怎样除去

2024/3/20 3:10:33发布39次查看
这次给大家带来路径中#号怎样除去,路径中#号除去的注意事项有哪些,下面就是实战案例,一起来看一下。
在开发过程中发现路径中带有/#/的标示,而且还去不掉,很丑陋。
众所周知,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再也没有#了,多完美
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
使用es6中class模仿vue做出双向绑定
关于vue绑定问题解析
以上就是路径中#号怎样除去的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product