-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Motivation
Currently, when a Route component is declared to be a match, the matching path is not implicitly available for inner routers or routes. In other words: Even though we can confidently state that the URL is there (because the route matched), one has to repeat the path segments that we know already matched in routers or routes that are found in the matched Route component's children. This seems to be redundant work for the developer.
An example:
<Router basePath={import.meta.ENV.BASE_URL}>
<Route path="/admin" and={isAdmin()}>
<!-- The internal admin router: Must repeat the path (/admin) -->
<Router id="redundant" path="/admin">
...
</Router>
<!-- Much nicer would be to simply type: -->
<Router id="inheriting">
...
</Router>
</Route>
</Router>Technical Requirements
- Currently, the RouterEngine class takes care of path inheritance. It needs to be decoupled.
- The decoupled solution must be available through Svelte's context mechanism.
- Only
Routecomponents with a stringpathproperty value can automagically contribute. Routecomponents withoutpathcannot contribute.Routecomponents with arestparameter will contribute excluding the rest of the path.
As bonus, Route components that have its path specified via a regular expression should accept a path provider property that accepts a function that returns the path to be contributed contextually. Something like this, perhaps:
<script lang="ts">
function calculatePathContext(routeCtx: TypeToBeDefined) {
return `${routeCtx.basePath}/users/${routeCtx.params.userId}`
}
</script>
<Route path={/users\/(?<userId>\d+)/i} pathCtx={calculatePathContext}>...</Route>Basically, allow a function to provide a calculation of the path segments to be contributed.
If this bonus is added, then the technical requirement would be to always use pathCtx if provided, and otherwise fall back to the requirements listed above.