Migrate to new Data API #10236
-
Hi!
App component:
The That what I tried:
App component:
But as expected I am getting an error: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Any help here would be appreciated |
Beta Was this translation helpful? Give feedback.
-
This is because you're using const router = createHashRouter(
createRoutesFromElements(
<Route element={<Layout />}>
<Route path="/" element={<Home />} />
{/* More Route components here */}
</Route>,
),
);
const Layout: FC = () => {
const location = useLocation();
useEffect(() => {
// Doing something with the location.pathname here
}, [location.pathname]);
return <Outlet />
}
export const App: FC = () => {
return <RouterProvider router={router} />;
}; |
Beta Was this translation helpful? Give feedback.
This is because you're using
useLocation
outside ofRouterProvider
. Instead, you can move anything global like the outer logic in yourApp
component to a root layout component so it's inside the router: