Skip to content

Issue with React Router v6 Causing Full Page Reload on Sidebar Navigation #4210

Answered by krisantrobus
Clinton-dev asked this question in Q&A
Discussion options

You must be logged in to vote

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.

const handleClick = (
    event: React.MouseEvent<HTMLAnchorElement>,
    path: string
  ): void => {
    event.preventDefault();
    navigate(path);
  };

You will no longer need the to or as in this case. The href should be included for to keep the the component accessible

<SidebarNavigationItem
    icon={<ProductContactCenterAdminIcon decorative={false} title="Admin" />}
    selected={window.location.pathname === '/'}
    href="/"
    onClick={(event): void => {
      handleClick(event, "/");
    }}
>
    Dashboard
</Si…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Clinton-dev
Comment options

Answer selected by Clinton-dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants