You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And needed to setup two url schemas based on the turned on feature flag =)
I have used useCustomLocation to do smth like that:
export function useCustomLocation(): HookReturnValue<LocationHook> {
const [location, setLocation] = useBrowserLocation();
const featureFlags = useFeatureFlags();
const appSetLocation = useCallback(async (to: Path, options?: { replace?: boolean }) => {
const destination = isNewSchemeRequired(to, featureFlags) ? getUrlFromNewScheme(to) : to;
setLocation(destination, options);
}
}, [setLocation]);
return [location, appSetLocation];
}
<Router hook={useCustomLocation}>
{/* when components here call useLocation the useCustomLocation will be used */}
</Router>
That allows to update ALL routing without touching the business code, which is very good for the current case. I would like to do smth like that for useRoute as well, however, have not found in properties of Router ability to override that, so currently I have done:
useSystemRoute(route) {
const res = useRoute(route);
// do some custom stuff
return res;
}
I think extending router with all hooks maybe also beneficial in some cases when need to adjust behavior globally, for example, apply some custom logic on extraction of parameters (useParams), or when migrating some codebases with rules different from wouter conventions to wouter, etc.
The text was updated successfully, but these errors were encountered:
useRoute should already be compatible with custom hooks. We are not considering adding more hooks at this time to maintain the library's lightweight nature.
I have met the next requirement - there is an existing codebase where lot of urls are hardcoded, e.g.
And needed to setup two url schemas based on the turned on feature flag =)
I have used
useCustomLocation
to do smth like that:That allows to update ALL routing without touching the business code, which is very good for the current case. I would like to do smth like that for
useRoute
as well, however, have not found in properties ofRouter
ability to override that, so currently I have done:I think extending router with all hooks maybe also beneficial in some cases when need to adjust behavior globally, for example, apply some custom logic on extraction of parameters (
useParams
), or when migrating some codebases with rules different from wouter conventions to wouter, etc.The text was updated successfully, but these errors were encountered: