Skip to content

Instantly share code, notes, and snippets.

@imjakechapman
Last active April 12, 2020 17:28
Show Gist options
  • Select an option

  • Save imjakechapman/82b37477db348fa6af828f111c1dc0b3 to your computer and use it in GitHub Desktop.

Select an option

Save imjakechapman/82b37477db348fa6af828f111c1dc0b3 to your computer and use it in GitHub Desktop.
// V5
<Router>
<Switch>
<Route path="/one" component={ViewOne} />
<Route path="/two" component={ViewTwo} />
<Route path="/three" component={ViewThree} />
<Route render={() => <Redirect to="/one" />} />
</Switch>
</Router>
// V6
<Router>
<Routes>
<Route path="/one" element={<ViewOne />} />
<Route path="/two" element={<ViewTwo />} />
<Route path="/three" element={<ViewThree />} />
<???>
</Routes>
</Router>
// Possible new way of handling
<Router>
<Routes>
<Route path="/one" element={<ViewOne />} />
<Route path="/two" element={<ViewTwo />} />
<Route path="/three" element={<ViewThree />} />
<Route path="*" element={<SelfRedirect path="/one" />} />
</Routes>
</Router>
const SelfRedirect = ({ path }) => {
let navigate = useNavigate();
useEffect(() => {
navigate(path);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment