Closed pleek91 closed 1 week ago
Name | Link |
---|---|
Latest commit | 547f4c28369e04157f4410bc228a252eef3076e5 |
Latest deploy log | https://app.netlify.com/sites/kitbag-router/deploys/667b8db80ba9a50008371642 |
Deploy Preview | https://deploy-preview-209--kitbag-router.netlify.app |
Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
Description
This PR updates the type for the current route to be a discriminating union of possible routes. This means that when accessing the route via
router.route
or by using theuseRoute
composition the route can easily be narrowed.Given the following routes
router.route.key
is type'parentA' | 'parentB' | 'parentA.childA'
. Androuter.route.params
is type{} | { paramA: string }
. Which means you can narrow the route in a type safe way by doing things like thisisRoute
anduseRoute
This gets even more useful when combined with the
isRoute
type guard that is exported by router. By defaultisRoute
is not an exact route match, meaning it will match any route AND any children of that route.If you want to match only an exact route you can pass the exact option into
isRoute
This works exactly the same when using
useRoute
This makes working with routes in a type safe way much easier and more flexible.