Skip to content

Add a resolve() function to build URL's for routes with parameters #73

@webJose

Description

@webJose

Motivation

This is twofold: DRY on route paths. It would be nice if we only need to define the route path in the Route component without needing it somewhere else. The second reason is that enables a (reusable) component to produce URL paths by receiving the resolve() function, route key, and maybe also the parameter values. Maybe the reusable component can provide the latter. I guess it is implementation-dependent.

Technical Details

  1. Routes that don't specify the path property or the value of the path property is a regular expression, then they must specify the template property, which would be a new addition to the Route component.
  2. Routes that specify the path property with a string don't need anything extra, but if the template property is given, then the latter wins.

This should start with a global function:

declare function resolve(router: RouterEngine, key: string, paramValues?: Record<string, any>): string;

If the paramValues is not given, the current route parameter values are used (available in RouterEngine.routeStatus) so long the route has matched.

Then, to simplify use, a bound resolve() function should be provided to children of routers and routes via the children snippet.

This brings us to something: The growth of the children parameters. At this point, it should be evident that a single RouterContext and RouteContext argument is best for the children snippets of the components.

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority: MediumMedium priority. Upvote to request a higher priority. Downvote to attempt to lower priority.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions