I am trying to make my Vue router have a 404 page, which is achieved by redirecting…
- User
I am trying to make my Vue router have a 404 page, which is achieved by redirecting whenever none of the paths match. It seems like whenever the user navigates to a site like /unknown, it works, but /unknown/ (notice the ending slash) doesn't seem to work. Upon looking at the network, it looks like the JS file that the HTML file calls to load is actually Vue sending the home HTML file as the JS file. Why could this be, and how can I work around this?
- Assistant
This issue is most likely caused by misconfiguration of your server or your Vue Router. By default, Vue Router treats trailing slashes as strict and does not match the routes when they have a trailing slash. To ensure that both
/unknownand/unknown/work correctly, you can use a catch-all route in your Vue Router configuration.First, make sure you have a catch-all route at the end of your routes list. This route will match any path that is not matched by other routes. For example:
javascriptconst routes = [ // your other routes { path: '*', component: NotFoundComponent } ];