sveltejs / sapper

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

Include index.html as part of the routes regex #1270

Open garciadiazjaime opened 4 years ago

garciadiazjaime commented 4 years ago

Describe the bug I have a static version of an app hosted on a static server. The main route works fine, however other sections when refreshed, the static server redirects them to /route/index.html. Which breaks the pages because they don't load the JS.

After looking at client.js I found that the routes regex look like this:

 {
    pattern: /^\/map\/?$/,
    parts: [{
        i: 3
    }]
}

Giving the request is redirected to /map/index.html the regex returns false and the JS is not loaded.

To Reproduce

The page works just fine, you can see a map.

You won't see the map.

I manually edited the regex for one of the routes like this /^\/stats\/?(index\.html)?$/ and it works (on the client.js file).

Unfortunately static server providers like Google Buckets or S3 do the redirect automatically so there isn't much we can do there, however just extending the route regex fixes the issue.

Is there any way to incorporate this?

I'm big fan of sapper, thanks for your effort!

benmccann commented 4 years ago

One thing I would worried about is that you would now have two pages that could show the same content (one with index.html and one without), which might cause a duplicate content penalty in search engines, so I'd be nervous about adding this by default for all sites

garciadiazjaime commented 4 years ago

hey @benmccann,

First of all, thanks for the quick response!

If you access the path directly (ie. http://food.mintitmedia.com/map) it redirects (301) to index.html so the content won't be duplicated.

I think this only applies to apps hosted on S3 or Google Buckets (I assume other providers do the same, but not sure); I agree with you, it might not be an issue for everyone.

However If a user or bot hits the URL path directly they got a broken experience since the JS isn't loaded, I think this is more severe than been penalized by search engines, although considering it does a 301 I don't think it applies.

a) Any way we can play with ROUTING, like calling the file name.**html**.svelte and if that's the case then the regex will include the index.html part?

b) any way to extend the routes through rollup.config.js?

Or what's the recommendation?

Cheers.

antony commented 4 years ago

Without looking into this too deeply, have you tried calling your routes index.html.svelte and then trying to visit index.html?