Adobe-Marketing-Cloud / aem-guides-wknd-events

Step by Step guide to creating a Single Page Application to use with AEM
48 stars 34 forks source link

[React] How do we handle 404 error AEM SPA editor? #80

Open khus29 opened 4 years ago

khus29 commented 4 years ago

Local Environment Before filing an issue, verify that the prerequisite tools/software are installed:

Describe the issue If user hit any route which does not exists, 404 error, then how do we handle it? What is the standard way to handle it - at AEM end or at react end?

viveksachdeva commented 4 years ago

Hi,

are there any recommendations or documentation around this? ACS commons error handler doesnt work with this

viveksachdeva commented 4 years ago

I got it to work using ACS Error handler with some modification in 404.jsp... The issue is that error handler returns path of 404 page as <404page>.html irrespective of the whether originating request is from HTML, or JSON.. In case of SPA, any junk url gets internally redirected to 404.html which calls its model.json for data which again is a junk URL and gets redirected to 404.html instead of 404.model.json,. We want 404.model.json to be a normal request returing JSON data.. Doing this made 404 page render perfectly..

Hope this helps :)