onMatch beforeLoad onLoaded #391
Replies: 1 comment
-
U can ignore question did realize there much better way to handle menu items behavior that dont use useRoute for handling clicks and active props `import * as React from 'react'; type RouterNavLinkProps = { export const RouterNavLink = (props: RouterNavLinkProps) => { const { href, onClick, onFocus, onMouseEnter, onMouseLeave } = link; return ( export default RouterNavLink;` |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
old version onMatch always have params and search included and wass really nice to use for updating menu items based on params.
onLoaded have params but its too late to update menu there becouse if using useRoute to hadle onClick behaviour in menu items it happens later and useRoute gives errors.
beforeLoad its now perfect place to update menu items and check auth etc but for now only context defined there.
I did try to modify beforeLoad in router and something like this works perfectly for my needs but not sure if its right sloution
await Promise.all( matches.map((match) => match.options.beforeLoad?.({ context: router.context, params: match.params, search: match.routeSearch, }), ), )
Beta Was this translation helpful? Give feedback.
All reactions