这次给大家带来Vue怎样剔除路径#号,Vue剔除路径#号的注意事项有哪些,下面就是实战案例,一起来看一下。
众所周知,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再也没有#了,多完美
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
以上就是Vue怎样剔除路径#号的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号