name: string | Symbol - unique and will be used to identify a route when needed (e.g. we might provide a function to generate a url from route + params + searchParams )
rule: Regexp - will be used to match routes. Named capture groups can be used to provide some params (e.g. id)
handle: Function that receives route matching info and performs necessary async action to load/activate a route. This can mean importing js, doing misc requests or redirecting. It can return dom content to be rendered (html or nothing).
Matching routes should done with a function (called match) that:
received url and routes
parses url returning a info object
matches routes against url info
returns matching route and parsed url info or undefined (RouteMatch)
We should provide a useRoutes function/hook to make this easier to use:
receives routes
listens to url changes :
match route
awaits for matching route's handle (should pass url info)
stores route and it's handling result/status in local state
returns matched route and it's handling result/status state
With these changes cosmoz-pager-router should:
call useRoutes to get status of currently matched route
render route's content (if return by handle in useRoutes)
render loading states (configurable)
render not found content (configurable) when no routes matches
We should also provide url handling utilities like replace and navigate.
Define routes (
Route []
) as a list/map of:id
)html
ornothing
).Matching routes should done with a function (called
match
) that:url
and routesWe should provide a
useRoutes
function/hook to make this easier to use:routes
match
routeWith these changes
cosmoz-pager-router
should:useRoutes
to get status of currently matched routeWe should also provide url handling utilities like
replace
andnavigate
.