maplibre / ngx-maplibre-gl

Angular binding of maplibre-gl
https://maplibre.org/ngx-maplibre-gl/
MIT License
65 stars 25 forks source link

Demo page SPA is not working as expected #153

Closed HarelM closed 2 months ago

HarelM commented 3 months ago

This is described here basically: https://github.com/isaacs/github/issues/408

Steps to reporduce:

  1. Go to https://maplibre.org/ngx-maplibre-gl/
  2. Click on examples
  3. Click on any example
  4. Refresh the browser --> You'll get 404

This is because a SPA page assumes the server will return the index.html file for every unknown route, which doesn't happen in github as is explained in the issue above.

The proposed solution there is to create redirects in cloudflare or use the instructions described here: https://github.com/rafgraph/spa-github-pages

@birkskyum let me know if you would like to try out the CDN redirect.

HarelM commented 3 months ago

I've made a test to see if the above repo solution works and it looks like it does. I've manually changed the gh-pages branch by adding the 404.html file with 1 as the segment path and added the relevant part to the index.html file. Not sure how this will affect the local dev environment though.

birkskyum commented 3 months ago

This 404 setup + lot's of redirecting first to, and then away from, /?/ is really a last resort imo as it'll i.e. never be able to work with SEO, caching etc.

What is technically blocking fixing it at the origin cause and pre-rendering these pages?

HarelM commented 3 months ago

I've never used angular with SSR so my knowledge here is limited. From what I can tell the following is what you are referring to, right? https://angular.io/guide/prerendering Adifferent solution is the following SSR requires server side configuration, which won't work with github pages as far as I can tell: https://angular.io/guide/ssr#why-use-ssr

Yea, the 404 setup won't work well with SEO as far as I can tell.

birkskyum commented 3 months ago

Yes, the first link is what I'm referring to - or in the new docs (think content is the same) , but angular.io will be sunset soon: https://angular.dev/guide/prerendering#how-to-prerender-a-page

HarelM commented 3 months ago

I'll look into it, thanks for the idea!

HarelM commented 3 months ago

I've spent like an hour on this, getting no where. See here: https://github.com/angular/angular/issues/54965 It's extremely undocumented in google and it seems like version 17 incorporated an external package so all the examples are out dated, I think. Not sure it's worth the extra effort. I tend to make the current workaround an official solution until someone decides that it might interest them enough to do it and open a PR here. I can leave this issue open in case someone stumbles on this in the future.

atty57 commented 3 months ago

This seems to work can you check again

HarelM commented 3 months ago

I have added a 404.html file, but it's not a great solution. Having said that, I was not able to prerender the angular showcase app.

birkskyum commented 3 months ago

At least the 404 works! :)

HarelM commented 2 months ago

Seems like the above PR with the SSR prerendering solve this issue well. Thanks @birkskyum and @marcjulian!!