Home > OS >  Vue route path can't match a param with suffix
Vue route path can't match a param with suffix

Time:09-22

I have a route

{
  path: '/file/:fileId'
}

when I visit

http://.../file/abc

It's worked, I can get fileId is abc

But, when I visit

http://.../file/abc.jpg

The chrome return 404, The vue router not work.(maybe vue is not work too...)

How can I get the abc.jpg for fileId.

CodePudding user response:

When you are reaching abc.jpg, you're asking the server to return you an actual file (that would be stored there).

This is also not actually a viable file, you cannot have .jpg at the end, only .html, .htm and maybe a few others are allowed. Nowadays you don't even need them due to server configuration.

Even less in an SPA context with a JS-based router that only emulates actual server resources access.

TDLR: it doesn't work because it is not meant to work.

CodePudding user response:

Unless you are doing server stuff where you have control of the server on what to do if that route is matched, the Vue Router code isn't even being loaded yet and by default, the server you are using is most likely configured to look for an actual file if the path ends with an extension. If it is not able to, it returns 404.

  • Related