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
Hi,
First of all - many thanks for the great package!
I've encountered an issue similar to one in #36. However, as the package update helped in main project, the issue still occurs in Storybook story. It's set up with MemoryRouter - it's the only difference compared to main app.
What I did is - in app, I added the change below:
// Hook usageconstlocation=useLocation();constbreadcrumbs=useBreadcrumbs(undefined,undefined,location);// Copied useBreadcrumbs code added locally in appconstuseReactRouterBreadcrumbs=(routes?: BreadcrumbsRoute[],options?: Options,// The location is now added as third parameterlocation?: Location,): BreadcrumbData[]=>getBreadcrumbs({routes: routes||[],// Using provided location makes the error mentioned in title gonelocation: location||useLocation(),
options,});
As you can see, when I use "useLocation" explicitly and pass the results as third, additional parameter, the hook works fine both in app, as well in Storybook.
I can submit a small PR for this change, yet I'm not sure if anyone else had similar issue and if this even the best fix possible.
hi @jakubzet - Can you post an example of your storybook story? I think the original error Error: useLocation may be used only in the context of a <Router> is because <Router> is a provider that useLocation needs. So maybe you'd have to wrap the entire story with it?
Hi,
First of all - many thanks for the great package!
I've encountered an issue similar to one in #36. However, as the package update helped in main project, the issue still occurs in Storybook story. It's set up with MemoryRouter - it's the only difference compared to main app.
What I did is - in app, I added the change below:
As you can see, when I use "useLocation" explicitly and pass the results as third, additional parameter, the hook works fine both in app, as well in Storybook.
I can submit a small PR for this change, yet I'm not sure if anyone else had similar issue and if this even the best fix possible.
EDIT: What could be important is that I use new, V6 useRoutes API (as described in docs: https://reactrouter.com/docs/en/v6/getting-started/concepts#defining-routes)
The text was updated successfully, but these errors were encountered: