vue路由在history模式下,在非根目录下报404错误

解决方法
找到src/router/index.js 文件添加代码
export default new Router({
  mode: 'history', //修改部分
  base: '/dist',  //修改部分 如果你的次级文件夹名是dist 这里就配置dist
  routes: [
    {
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld
    },
    {
      path: '/test.html',
      name: 'Hello',
      component: Hello
    }
  ]
})

如果你是Apache服务器,找到httpd.conf配置文件LoadModule rewrite_module modules/mod_rewrite.so这行代码去掉‘#’号 保存, 重启Apache

然后在你dist文件夹下新建.htaccess 加入下面代码,官网那个方法测试报错

RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /dist/index.html [L]  //注意这个

如果你是nginx服务器 在跟目录下

location / {
  try_files $uri $uri/ /index.html;
}

不在跟目录下

location /your_router {
  try_files $uri $uri/ /your_router/index.html;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值