Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch-all rules [...param] should end with a star * #412

Open
jods4 opened this issue Jun 5, 2024 · 6 comments
Open

Catch-all rules [...param] should end with a star * #412

jods4 opened this issue Jun 5, 2024 · 6 comments
Labels
📚 docs related to documentation

Comments

@jods4
Copy link

jods4 commented Jun 5, 2024

Naming your file [...path].vue generates the router path :path(.*).
This is documented here: https://uvr.esm.is/guide/file-based-routing.html#catch-all-404-not-found-route

Vue Router documentation recommends using a repeated regex for catch-all routes, i.e. :path(.*)* (note extra star at the end).
See: https://router.vuejs.org/guide/essentials/dynamic-matching#Catch-all-404-Not-found-Route

There difference is subtle but observable.

First: the path parameter is a string "/a/b/c" with unplugin, and a parsed array ["a", "b", "c"] with router syntax.

Second: I would like to navigate to a catch-all route with a specific URL. It's impossible to do with unplugin, consider this:

// Unplugin :path(.*)
router.push({ name: "catch-all", params: { path: "a/b/c" } })
// Location is escaped into: /a%2fb%2fc

// Vue Router : path(.*)*
router.push({ name: "catch-all", params: { path: ["a", "b", "c"] })
// Location is /a/b/c
@posva
Copy link
Owner

posva commented Jun 5, 2024

This could be documented and it’s possible with [[...path]]+

@jods4
Copy link
Author

jods4 commented Jun 5, 2024

Thanks for the tip! Only difference with * is that empty route is not accepted, something that doesn't matter in my case.
I'm gonna use that.

@jods4
Copy link
Author

jods4 commented Jun 6, 2024

@posva I tried to use [[..path]]+ and found two issues:

  1. The params types generated by unplugin-vue-router are incorrect, path should be an array.
  2. Looks like (on Windows at least) plus signs in paths cannot be fetched (using Vite).

Failed to fetch dynamically imported module: http://localhost:6357/Modules/[...path]+.page.vue

My guess is this is an escaping issue. + in URL are an escape for a space . As it's part of the real filename I suppose it should have been escaped as %2B.

@posva
Copy link
Owner

posva commented Jun 6, 2024

Wouldn’t 2 be a vite bug? I can’t test it

@jods4
Copy link
Author

jods4 commented Jun 6, 2024

I'm not sure, I would need to debug.

The message quoted above is found in browser console. That doesn't look like the right URL for the browser to fetch a file named [...path]+.vue because that URL would decode into [...path] .vue (with a space).

So my guess at the moment is that unplugin-vue-router should generate a route with component: import('./[..path]%2B.vue')... but that's just a guess at this point.

How are other escapes handled, for example if I name my file %&/.vue? I suppose that falls in the same category.
Sorry I do not have time to dig into this further right now, will try to come back to this later.

Copy link
Owner

posva commented Jun 6, 2024

No worries, the help is already appreciated!
This plugin doesn’t do anything in terms on encoding, it expects the other tools to handle
IIRC + is decoded as space in the query (not in the path) but not by everything 😅

@posva posva added the 📚 docs related to documentation label Jun 17, 2024
@posva posva linked a pull request Jun 19, 2024 that will close this issue
@posva posva removed a link to a pull request Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 docs related to documentation
Projects
Status: 🆕 New
Development

No branches or pull requests

2 participants