stereobooster / react-snap

👻 Zero-configuration framework-agnostic static prerendering for SPAs
MIT License
5.04k stars 391 forks source link

Crawl private page #330

Closed juanse254 closed 5 years ago

juanse254 commented 5 years ago

When the crawler goes through the pages it gathers most of them, the ones that were not crawled can be included using the "include" on the package.json. Regardless i have a customer panel page, where the user must login first before visiting. I can login to the panel but whenever i hit refresh on a page that was not crawled before then i get a not found error.

So:

user->panel page -> refresh(f5) on browser -> not found error (because it wasn't crawled because it requires login).

Is there any workaround that doesn't involve modifying my client so if its 'react-client' i display the private page?

stereobooster commented 5 years ago

Is there any workaround that doesn't involve modifying my client so if its 'react-client' i display the private page?

The only solution I can see is to prerender "shell" page (some navigation, but without content), and serve instead of 404 for your protected pages. You can also modify source of your app to serve some placeholder pages if it is in prerendering phase

juanse254 commented 5 years ago

Is there a way to redirect to the app when hitting refresh rather than trying to reload a directory that does not exist? when i load the page and i click through the links, the behavior is expected. When i try to refresh pages thats were the problems start, i managed to solve most of them but the private pages are an issue.

stereobooster commented 5 years ago

Do you use index.html or 200.html as 404 page?

juanse254 commented 5 years ago

No, should i?

stereobooster commented 5 years ago

oh wait but you use 404.html (generated by react-snap), right? You need to use 404.html or index.html or 200.html as 404 page. If you use any of those as 404 page it should work.

juanse254 commented 5 years ago

what about the real 404? what should i set in the react-router? i can set the component to the 200.html but then what if a user hits a 404 page then it would get redirected to the index.

Or is there a setting in react-snap to set the 404 page?

EDIT: @stereobooster thanks for the help, indeed since i don't use CRA but i do use react-route i had to set up a manual redirect in my nginx to ErrorDocument 404 to the 200.html and then it worked flawlessly.

thanks again @stereobooster great tool!

stereobooster commented 5 years ago

❤️

jersrej commented 3 years ago

Hi @juanse254 How did you fix the problem? Tho I'm using a react-router-dom and CRA and S3 serverless to deploy my application. Really appreciate this, I hope you can reply. Thank you!