Optional onRouted and onRoutedUnhandled parameters will be invoked for every matching route change
constonRoutedUnhandled=({name,props,path})=>{
console.log(name,'routed with props',props)
}
constApp:React.FunctionComponent=()=>{
constroute=useRouter({routes,onRoutedUnhandled})
// ...
}
or a collection of callbacks, one for each route
constonRouted={
user:({name,props,path})=>{},
faq:({name,props,path})=>{},
login:({name,props,path})=>{},
notFound:({name,props,path})=>{}
}
constApp:React.FunctionComponent=()=>{
constroute=useRouter({routes,onRouted})
// ...
}
Initial Route
When your component is first rendered and before the routing effect has fired, there will be a moment when the current route has not yet been determined. By default useRouter will return { name: 'loading', params: {} } until the actual route is determined. You can change this by passing in an initialRoute.