useLocation in v4
I'm using
but got Uncaught Error: useLocation() may be used only in the context of a <Router> component.
but got Uncaught Error: useLocation() may be used only in the context of a <Router> component.
useLocation hook outside of a router context. To fix this issue, make sure you're using the useLocation hook within a component that is wrapped by a router provider.Note: you can ask me a follow up question by @ mentioning me again useRouterContextApp.tsx <BrowserRouter>
<ConfigProvider >
<Refine
routerProvider={routerProvider}
resources={[
{
name: "web/quotation",
meta: {
label: "Quotations",
route: "quotation",
icon: <IoMailOpenOutline />,
},
list: QuotationList,
create: QuotationCreate,
edit: QuotationEdit,
show: QuotationShow,
},
...configuration
]}
>
<Routes>
<Route
element={
<Authenticated fallback={<Outlet />}>
<NavigateToResource resource="/" />
</Authenticated>
}
>
<Route
path="/login"
element={<Login />}
/>
</Route>
</Routes>
<RefineRoutes>
{(routes) => (
<Routes>
<Route
element={(
<Authenticated redirectOnFail="/login">
<CustomLayout>
<Outlet />
</CustomLayout>
</Authenticated>
)}
>
<Route index element={<NavigateToResource />} />
{routes}
<Route path="*" />
</Route>
</Routes>
)}
</RefineRoutes>
</Refine>
</ConfigProvider>
</BrowserRouter> {
name: "config",
meta:{
label: "Configuration Parent",
route: "config",
icon: <IoFileTrayStackedOutline/>,
}
},import { useRouterContext } from "@refinedev/core";
const MyComponent: React.FC = () => {
const { useLocation } = useRouterContext();
const location = useLocation();
const { products, code } = location.state as any;
// Your component logic here
};import { Refine } from "@refinedev/core";
import routerProvider from "@refinedev/react-router-v6";
import { BrowserRouter } from "react-router-dom";
const App: React.FC = () => {
return (
<BrowserRouter>
<Refine routerProvider={routerProvider}>
{/* Your components here */}
</Refine>
</BrowserRouter>
);
};