sveltejs / sapper

The next small thing in web development, powered by Svelte
https://sapper.svelte.dev
MIT License
7.02k stars 437 forks source link

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

Open will093 opened 2 years ago

will093 commented 2 years ago

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/...