sapper icon indicating copy to clipboard operation
sapper copied to clipboard

The page does not hydrate on the client after a URL rewrite

Open will093 opened this issue 4 years ago • 0 comments
trafficstars

Describe the bug

URL rewrites don't work with Sapper, the page does not hydrate an the client. The issue occurs when using any kind of redirect middleware, eg.

const rewriteUrl = () => {
  return (req, res, next) => {
    if (req.url === "/about2") {
      req.url = req.originalUrl = `/about`;
      next("route");
    } else {
      next();
    }
  };
};

To Reproduce

Example code here:

https://github.com/will093/sapper-url-rewrite-issue

On the route /about2, I am expecting the after the rewrite to load the same content as the /about page and hydrate it properly, instead it does a server render but then the app never hydrates on the client.

Expected behavior

Page whose URL gets rewritten should hydrate properly.

Severity

Severe

The issue is preventing me from setting up locale/market based routing for my site.

Additional context

Some context to my problem in case there is another way to do this with Sapper. I have different language/market based routes, like:

my-site.com/de/... my-site.com/se/...

And I want to use URL rewrites to set up something like this as a default:

my-site.com/... --> mysite.com/world/...

will093 avatar Sep 24 '21 07:09 will093