Created
February 22, 2021 20:08
-
-
Save dev-cyprium/067acdc7dddc0b78c18b4fffec809f64 to your computer and use it in GitHub Desktop.
Creating the router
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AppRouter = ({ children }) => { | |
| const [route, setRoute] = useState("/"); | |
| function push(newRoute) { | |
| setRoute(newRoute); | |
| } | |
| useEffect(() => { | |
| window.history.pushState({}, "", route); | |
| }, [route]); | |
| return ( | |
| <RouterContext.Provider value={{ route, push }}> | |
| {children} | |
| </RouterContext.Provider> | |
| ); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment