I understand that it's important to keep API set pretty limited on purpose.
However we are trying to do SSR + data loading + code splitting (by component), and the function like match() in react-router 3 is required.
I think at least pick() should be exposed for matching routes, and match . Besides, this function can also help to test routes.
Does the <Match /> component help?
@codepunkt When using Match(), we have to use renderToString() to get the result on server-side.
What's more the result will be wrapped with <BaseContext.Consumer> and <Location>.
https://github.com/reach/router/blob/master/src/index.js#L446
I just want something like matchPath() in react-router.
Suspense won鈥檛 require it so I didn鈥檛 expose it ... but I鈥檓 still thinking about it 馃槓
psssst
import { match } from "@reach/router/lib/utils"
match() can be done easily by:
let match = (path, uri) => pick([{ path }], uri);
The problem is that the most important logic part - matching routes with route ranking must be done with pick().
I think import { pick } from '@reach/router/lib/utils will be better but I don't know whether the pick() is stable or not.
oh I meant pick :P
Pick will always be what Router uses, so I guess it can be considered stable. It doesn鈥檛 handle nesting though, and again, I鈥檓 just waiting for Suspense to make this whole issue moot.
@ryanflorence how would Suspense solve a use case where you need to manually match some routes? For example to do a transition to a certain route. I get that this is not necessary for 90% of the users but it would be nice to export pick and the base context so you can do this yourself if you need to.
It would be nice to expose match/pick officially.
Those functions are notably used into Gatsby (here) and also benefit from users that need to extract params from url.
For TS users like me, the fact they are not exposed means nobody works on a TS def too. And using other components like path prop assigned to comps is not very convenient to type
Most helpful comment
psssst
import { match } from "@reach/router/lib/utils"