vue-router history模式,服务器配置后,访问报500错误

我的web服务器有二级目录promotion,于是配置了routerconfig

//项目源码目录/src/router/index.js
import Vue from "vue";
import Router from "vue-router";
import notFound from "@/components/notFound";
import index from "@/views/index";

Vue.use(Router);

export default new Router({
  mode: "history",
  base:"/promotion/",
  routes: [
    { path: "*", component: notFound },
    {
      path: "/index",
      name: "index",
      component: index
    }
  ]
});
//项目源码目录/config/index.js
build: {
    // Template for index.html
    index: path.resolve(__dirname, '../dist/index.html'),

    // Paths
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: 'static',
    assetsPublicPath: '/promotion/',
}

服务器用的IIS管理,网站根目录配置了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="/promotion/" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

最终访问地址,域名/promotion/index,页面报了500错误,这是什么原因?怎么解决?

clipboard.png

阅读 5.7k
1 个回答

router中配置的base:"/promotion/"去掉

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题