Issue with React Router v6 Causing Full Page Reload on Sidebar Navigation #4210
-
Hi, I'm implementing routing with React Router v6 in <SidebarNavigationItem
icon={<ProductContactCenterAdminIcon decorative={false} title="Admin" />}
href="/"
as={Link}
to="/"
selected={window.location.pathname === '/'}
>
Dashboard
</SidebarNavigationItem>
<SidebarNavigationItem
icon={<ProductContactCenterTasksIcon decorative={false} title="Trips" />}
href="/trips"
as={Link}
to="/trips"
selected={window.location.pathname === '/trips'}
>
Trips
</SidebarNavigationItem> How can I prevent the full page reload and enable proper client-side navigation? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Disclaimer: This is a very experimental bot using OpenAI's GPT-4. The answers may not be correct, a human will review the answer and update it if necessary. To prevent the full page reload and enable proper client-side navigation with React Router v6 in your Here's how you can adjust your implementation: import { Link } from 'react-router-dom';
// Wrap SidebarNavigationItem with Link
<Link to="/">
<SidebarNavigationItem
icon={<ProductContactCenterAdminIcon decorative={false} title="Admin" />}
selected={window.location.pathname === '/'}
>
Dashboard
</SidebarNavigationItem>
</Link>
<Link to="/trips">
<SidebarNavigationItem
icon={<ProductContactCenterTasksIcon decorative={false} title="Trips" />}
selected={window.location.pathname === '/trips'}
>
Trips
</SidebarNavigationItem>
</Link> In this adjusted implementation, the For more details, you can refer to the solution found in the Paste documentation: https://github.com/twilio-labs/paste/blob/main/packages/paste-website/src/components/site-wrapper/sidebar/SidebarAnchor.tsx I also did a search, and I managed to find these other Discussions that might be similar or related to your question. Give them a read to see if they answer your question. If they do, head back here and update this discussion and mark it as answered, pointing others to the related discussion:
|
Beta Was this translation helpful? Give feedback.
-
Hey there, @Clinton-dev! I'm here to help you out with your React Router v6 issue. Let's get this sorted out! To prevent a full page reload and enable proper client-side navigation with React Router v6 in your
By addressing these points, you should be able to achieve client-side navigation without a full page reload. To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
Beta Was this translation helpful? Give feedback.
-
Hi @Clinton-dev, thank you for reaching out to us. One thing you can try is to utilize the const handleClick = (
event: React.MouseEvent<HTMLAnchorElement>,
path: string
): void => {
event.preventDefault();
navigate(path);
}; You will no longer need the <SidebarNavigationItem
icon={<ProductContactCenterAdminIcon decorative={false} title="Admin" />}
selected={window.location.pathname === '/'}
href="/"
onClick={(event): void => {
handleClick(event, "/");
}}
>
Dashboard
</SidebarNavigationItem> Let us know if this resolves your issue. |
Beta Was this translation helpful? Give feedback.
Hi @Clinton-dev, thank you for reaching out to us. One thing you can try is to utilize the
useNavigate
hook for the router and prevent the default navigation like below.You will no longer need the
to
oras
in this case. Thehref
should be included for to keep the the component accessible