You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed that there is no way to force a 301 redirect from React code (not from ssr.js). I tried the following:
Use res.redirect(301, url) (using useServerContext()) but this throws an error "Cannot set headers after they are sent to the client"
Use <Redirect> component but this one always uses a 302 because the return status is hard-coded in @salesforce/pwa-kit-react-sdk/ssr/server/react-rendering.js
So the first question would be if there is any way to solve the first error.
But, in any case, my proposal here is to allow passing a custom status when redirecting, following the example of the React Router documentation, you could add a new component to PWA Kit:
constRedirectWithStatus=functionRedirectWithStatus({status, ...props}){return(<Routerender={({staticContext})=>{if(staticContext)staticContext.status=statusreturn<Redirect{...props}/>}}/>)}// Use it like thisreturn<RedirectWithStatusstatus={301}to={...}/>
But as I said, in order to support that on the server there's a change needed in @salesforce/pwa-kit-react-sdk/ssr/server/react-rendering.js file:
The motivation for this is purely SEO. If you want to redirect to the canonical URL, or migrate old URLs to a new structure, etc. the crawlers need to understand this is a permanent redirect (301) to not index both pages.
Looking forward for any feedback and hopefully for this to get implemented into pwa-kit :)
Thanks!
The text was updated successfully, but these errors were encountered:
Hi!
I noticed that there is no way to force a 301 redirect from React code (not from ssr.js). I tried the following:
res.redirect(301, url)
(usinguseServerContext()
) but this throws an error "Cannot set headers after they are sent to the client"<Redirect>
component but this one always uses a 302 because the return status is hard-coded in@salesforce/pwa-kit-react-sdk/ssr/server/react-rendering.js
So the first question would be if there is any way to solve the first error.
But, in any case, my proposal here is to allow passing a custom status when redirecting, following the example of the React Router documentation, you could add a new component to PWA Kit:
But as I said, in order to support that on the server there's a change needed in
@salesforce/pwa-kit-react-sdk/ssr/server/react-rendering.js
file:The motivation for this is purely SEO. If you want to redirect to the canonical URL, or migrate old URLs to a new structure, etc. the crawlers need to understand this is a permanent redirect (301) to not index both pages.
Looking forward for any feedback and hopefully for this to get implemented into pwa-kit :)
Thanks!
The text was updated successfully, but these errors were encountered: