Skip to content

Instantly share code, notes, and snippets.

@dev-cyprium
Created February 22, 2021 20:08
Show Gist options
  • Select an option

  • Save dev-cyprium/067acdc7dddc0b78c18b4fffec809f64 to your computer and use it in GitHub Desktop.

Select an option

Save dev-cyprium/067acdc7dddc0b78c18b4fffec809f64 to your computer and use it in GitHub Desktop.
Creating the router
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