Skip to content
Discussion options

You must be logged in to vote

Hi there @vanaver! I ran your code and noticed the issue lies in how the router is being set up inside the App component.

You're creating a new router instance on every render by calling createBrowserRouter inside the function body. This results in React Router remounting components on every render, which can cause unexpected behavior like state resets and lost navigation history.

To fix this, you should move the router definition outside of the component, or better yet, use the standard BrowserRouter with Routes, which offers a more stable and idiomatic setup.

Here’s a simplified and recommended way to structure your App.js using BrowserRouter:

import React, { useState, useEffect } from "…

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
3 replies
@vanaver
Comment options

@0xtbarkan
Comment options

@vanaver
Comment options

Comment options

You must be logged in to vote
1 reply
@vanaver
Comment options

Comment options

You must be logged in to vote
1 reply
@vanaver
Comment options

Answer selected by vanaver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Ask and answer questions about GitHub features and usage Programming Help Discussions around programming languages, open source and software development
4 participants