How do I route to longer URL paths with history mode?
example: /catalog/[product-name]/p/[product-id]
The site just goes blank with history mode on. With errors of the following type on my CSS and JS
Refused to execute script from '{URL}/catalog/[product-name]/p/dist/build.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
router code:
const router = new VueRouter({
mode: 'history',
routes: [
{ path: '/catalog/my-product-name/p/MASN123U', name: 'product', component: product }
]
})
Side note: It works fine without history mode, just that the URL reads
/#/catalog/[product-name]/p/[product-id]
Web.config is as per the docs
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="SPA Routes" stopProcessing="true">
<!-- match everything by default -->
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<!-- unless its a file -->
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<!-- or a directory -->
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<!-- or is under the /api directory -->
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
<!-- list other routes or route prefixes here if you need to handle them server side -->
</conditions>
<!-- rewrite it to /index.html -->
<action type="Rewrite" url="/index.html" />
</rule>`enter code here`
</rules>
</rewrite>
</system.webServer>
</configuration>
From the error:
Refused to execute script from '{URL}/catalog/[product-name]/p/dist/build.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
Look somewhere in your HTML files, you probably have a script tag as such:
<script src="dist/build.js"></script>
When its path should be absolute, like:
<script src="/dist/build.js"></script>
Notice the /
added before dist
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With