开源项目 Meiam.System 打包部署后到IIS后,“登出”操作无法正常跳转

使用VsCode调试模式下,Logout后正常跳转到“登录页面”。 但是build打包后,部署到IIS下,Logout后就无法找到页面。经过相关资料查找,主要的原因还是Vuejs打包后 "history"路由引起的。

Vue框架提供了 HashHistory 两种路由模式。默认为 Hash 模式,但此模式下URL 中会存在“#”, 缺少美观,并且在微信中不允许URL存在“#”,所以很多人都会选择 “History"模式, 这套框架就是默认使用的”History"模式。

生产环境下解决方案:
一、修改为 Hash 模式 (对不牵涉到微信的项目可以使用)
修改项目 src / router / routers.js 文件

export default new Router({
  // mode: 'history',   //直接注释这行,默认即为Hash模式
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

二、 history 模式下

Internet Information Services (IIS)
安装 IIS UrlRewrite
在你的网站根目录中创建一个 web.config 文件,内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Handle History Mode and custom 404/500" stopProcessing="true">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="/" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

Apache

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

nginx

location / {
  try_files $uri $uri/ /index.html;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值