fusionjs / fusion-plugin-react-router

Migrated to https://github.com/fusionjs/fusionjs
MIT License
4 stars 21 forks source link

Support server-side route redirects to external url #245

Closed chrisirhc closed 5 years ago

chrisirhc commented 5 years ago

Type of issue

Feature request

Description

There seems to be no way to set up redirects (302s) to external urls. I understand this might be to keep consistent behavior with react-router v4's browser redirect behavior. Perhaps we can offer an <ExternalRedirect> component in fusion-plugin-react-router to workaround this? Alternatively, if there's some way of doing this otherwise, please document it.

Current behavior

Right now, in order to set up an external redirect route, I'm doing this. This method is clearly sub-optimal since the browser is loading the page with a null component just to redirect (and there's no way to leverage 302 status code here):

    <Route
      path={`/go-to-google`}
      render={() => {
        if (__BROWSER__) {
          window.location.href = 'https://www.google.com';
        }
        return null;
      }}
    />

Expected behavior

Support a syntax like:

    <Route
      path={`/go-to-google`}
      render={() => <Redirect to={"https://www.google.com"} />}
    />
mlmorg commented 5 years ago

It seems that react-router does not support this. We don't want to add support on top of react-router into this plugin, since it should just setup and use react-router. Perhaps this could be a ticket on react-router or a different plugin needs to be created.

chrisirhc commented 5 years ago

Does react-router have official support for server-side handlers? I'd think this would need to come from fusion.js since fusion's ctx is not something react-router would understand.

That probably means we need a separate plugin then. However, my thought was that it'd be an ask from other users of fusion.js .