vuejs 历史模式路由

asd*_*qwe 5 url url-rewriting vue.js vue-router vuejs2

如何使用历史模式路由到更长的 URL 路径?

例子/catalog/[product-name]/p/[product-id]

该网站只是在历史模式开启时一片空白。在我的 CSS 和 JS 上出现以下类型的错误

拒绝执行来自 '{URL}/catalog/[product-name]/p/dist/build.js' 的脚本,因为其 MIME 类型 ('text/html') 不可执行,并且启用了严格的 MIME 类型检查。

路由器代码:

const router = new VueRouter({
  mode: 'history',
  routes: [
    { path: '/catalog/my-product-name/p/MASN123U', name: 'product', component: product }
  ]
})
Run Code Online (Sandbox Code Playgroud)

旁注:它在没有历史模式的情况下工作正常,只是 URL 读取

/#/catalog/[product-name]/p/[product-id]

Web.config 根据文档

const router = new VueRouter({
  mode: 'history',
  routes: [
    { path: '/catalog/my-product-name/p/MASN123U', name: 'product', component: product }
  ]
})
Run Code Online (Sandbox Code Playgroud)

acd*_*ior 1

从错误来看:

拒绝执行“{URL}/catalog/[product-name]/p/dist/build.js”中的脚本,因为其 MIME 类型(“text/html”)不可执行,并且启用了严格的 MIME 类型检查。

查看 HTML 文件中的某个位置,您可能有这样的脚本标记:

<script src="dist/build.js"></script>
Run Code Online (Sandbox Code Playgroud)

当它的路径应该是绝对路径时,例如:

<script src="/dist/build.js"></script>
Run Code Online (Sandbox Code Playgroud)

注意/前面添加的dist.