#How to redirect to an external URL with `createBrowserRouter`?

1 messages · Page 1 of 1 (latest)

nova whale
#

So I have a createBrowserRouter that looks like this:

{
    path: "/",
    element: <Home/>,
  },
  {
    path: "/about",
    element: <About/>
  },
  {
    path: "/contact",
    element: <Contact/>
  },
  {
    path: "/demigod",
    element: <Shop/>
  },
  {
    path: "/demigod-kickstarter",
    element: <Navigate to="https://www.kickstarter.com/projects/no-name-games/demigod-0" />
  }

How do I get that bottom path to redirect to that URL without having to create a whole new component just to handle that redirect.

stray forum
#

It may not work, because redirect() might need to be a local route

#

but I don't recall

#

if redirect does need to be a local route, you can just do something like

useEffect(() => {
  // Simulate a mouse click:
window.location.href = "https://www.kickstarter.com/projects/no-name-games/demigod-0";
},[]);