AlexxNB / tinro

Highly declarative, tiny, dependency free router for Svelte's web applications.
MIT License
669 stars 30 forks source link

Non-exact routes capture wildcard contents as `params['*']` #40

Closed dimfeld closed 3 years ago

dimfeld commented 3 years ago

This exposes the contents of a matched wildcard to non-exact routes. It's most useful when the contents of the wildcard needs to be parsed further, used in a fetch request, and so on, but it may contain one or more slashes so a parameter like :foo won't work.

AlexxNB commented 3 years ago

Hmm... Thanks for great work. But it is important that every slug is a single parameter. Wildcard option is not easy to understand. It is simpler to get part of URL from the router object.

dimfeld commented 3 years ago

How would you recommend handling a case similar to this?

<Route path="app/*">
  <Route path="/authors/:author/*">
    ... other routes
    <Route path="/notes/*" let:params>
      <Notes type="author" path={params['*']} />
    </Route>
  </Route>

  <Route path="/books/:book/*">
     ... other routes
    <Route path="/notes/*" let:params>
      <Notes type="book" path={params['*']} />
    </Route>
  </Route>
</Route>

This is just a contrived example, not a real use case. But it's similar to what I have in mind, and it seems error-prone if you have highly nested routes and the Notes route and component has to try to figure out the entire parent URL context to know what part at the end to slice off.

AlexxNB commented 3 years ago

it shouldn't be in params. May be other variable where will be stored path of the route. I'll think about it. Same feature need to be to organize breadcrumbs for example.

dimfeld commented 3 years ago

Ok, thanks for your consideration!

AlexxNB commented 3 years ago

See new meta feature https://github.com/AlexxNB/tinro#route-meta It may help you.

dimfeld commented 3 years ago

Yes, I think that will work nicely. Thanks!