-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[v6] Discussion: Impact on SSR after removal of <Redirect /> #7267
Comments
Why would you need to change that (other than syntax and how the components used)? Instead of Redirect there is a Navigate component. I was looking over issues so I can start using v6 and I came across your question and thought I might want to do what you did. |
Are you asking why I can't use Apart from it being semantically incorrect there's a comment/warning here stating
|
Ah, got it. |
As of the latest alpha:
I find this confusing because I don't understand the static router context as being related (at least not exclusively) to navigating during the initial render. EG: application renders a 404 page in a StaticRouter and the SSR wrapper needs to know that it should set the statusCode on the response. |
I have the same question and one more about SSR. Previously I was able to get matched route with |
For the less involved, can you link to the original idea to remove? |
@dimaqq The only information I'm going by is the alpha release notes |
+1 for that question. If |
Just to be clear @Askadias, I believe that FYI: I was somewhat hoping that there might be some clarification with the remix run newsletter:
I'm still primarily confused about why there's an assumption that it needs to be "configured once on the client and once on the server". My use case for |
My use-case is pretty much similar. We apply a lot of various async logic based on query string in our OAuth application using redux. As result we get a redirect url and render it in router using |
What is the latest status of this? Does someone know if RR6 will support SSR? |
@suprMax I don't know, but removing SSR support from RR6 would be a major issue for a lot of people. I don't think anybody wants that. |
I'm cautiously optimistic that it won't be removed, I haven't tried RR6 myself yet. I think the amount of effort we've put at our company in keeping up with RR updates pretty much equals what would take to roll our own solution, so this update we will probably drop RR altogether if it's anything like 3->4. I wanted a bit of a heads up what to plan for. |
From the example in #7535, I ended up with something similar to this using <Routes>
<Route path="a" element={<A />} />
<Route path="b" element={<B />} />
<Route element={<Navigate to="a" />} />
</Routes> It seems to work correctly and is almost equivalent to |
@Zertz The problem is that Docs here for more details on how |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
@pseudo-su would it be an option to create your own |
Yes, it's possible. The reason I opened this issue is because I wasn't sure if this is/was a deliberate deprecation of SSR capabilities or not. Personally I think if the plan is to deprecate/remove the current documented way of doing SSR with react router it'd be a really good idea to at least update the current docs to clarify that things to do with SSR are going to be removed from That's the main reason I asked the question:
For what it's worth, I'm assuming the silence means that the change will be made and server rendering will be removed from It's not a massive inconvenience, but the lack of clarity makes it confusing as to whether people should be doing anything in preperation (if they use In case anyone's particularly curious, this is what I did to prepare for the removal of tl;dr basically I have a seperate // universal/app.js
function Dashboard() {
return <>
Home page
<CacheControl maxAge={200} />
</>
}
function Error404() {
return <>
<HttpStatus code={400} />
{/* etc */}
</>
}
function App() {
return (
<Switch>
<Route exact path="/" render={() => <Redirect to="/dashboard" />} />
<Route path="/dashboard" component={Dashboard} />
<Route path="/thing2" component={Thing2} />
<Route component={Error404} />
</Switch>
)
}
// client/index.js
const mountElement = document.getElementById('root')
hydrate(
<BrowserRouter>
<App />
</BrowserRouter>
mountElement
)
// server/index.js
function handler(ctx: koa.Context) {
const httpContext: HttpContextData = {
cacheControl: [],
statusCode: 200,
};
const renderedPage = render(
<HttpProvider context={httpContext}>
<StaticRouter location={ctx.request.url}>
<App />
</StaticRouter>
</HttpProvider>
)
// Redirect when <Redirect /> is rendered
if (httpContext.redirectLocation) {
// Somewhere a `<Redirect>` was rendered
ctx.redirect(httpContext.redirectLocation);
return;
}
// Handle status codes
ctx.status = 200;
if ([400, 401, 402, 403, 404].includes(httpContext.statusCode)) {
ctx.status = httpContext.statusCode;
}
// Set cache-control based on rendered content
const cacheControl = reconcileCacheControlOptions(httpContext);
const cacheControlValue = format(cacheControl);
if (cacheControlValue) {
ctx.set("Cache-Control", cacheControlValue);
}
ctx.response.body = wrapPageInHTMLTemplate(renderedPage);
} |
We (at work) will implement a RR alternative with full SSR support and API similar to RR5. I will link here once we have a stable implementation in production. Does anyone know when RR6 is going to be released? We will try to time it the same. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
For me worked to pass "*" as a path of the last route (
|
If you have defined the parent
|
Sorry to dig-up this old issue, but it has been automatically closed 3 years ago, and as far as I understand the discussion there is still no built-in way -without a "Data Router"- to detect redirection server side as it was possible with the |
I'm trying to reconcile how I've been using the
<Redirect />
component and figure out how the removal of<Redirect />
is meant to be translated into my "universal" react applications.tl;dr the removal of
<Redirect />
will break the mechanism I've been using to have a consistent redirect experience across server-rendering and client-rendering contexts. I'd like to put my case forward as to why the justification for removing<Redirect />
baffles me. Particularly the suggestion that "you should be doing it on the server anyway", because server-side redirects are precisely one of my use-cases for<Redirect />
.The way I have been using
<Redirect />
in the past on the server looks something like this (This won't work as-is but I'm just trying to articulate the gist of the important bits)The recommendation from change log of the v6 alpha is:
It sounds like it was removed with the assumption it would only affect people using it for client-side redirects... but I'm specifically using
<Redirect />
as a mechanism to have a unified redirect experience regardless of whether it's the first server-side render or subsequent client-side renders.The wording around needing to "do it on your server" implies to me that server-rendering is viewed to be outside the scope of
react-router
. Is this signposting a deliberate move away from having SSR capability inreact-router
going forward?Ultimately if that's the direction this project is going in I can work around it, but I'm looking for clarification first.
EDIT:
I found where this is currently mentioned in the docs so I'll add it here for completeness sake https://reacttraining.com/react-router/web/guides/server-rendering
The text was updated successfully, but these errors were encountered: