Skip to content
This repository has been archived by the owner on Jun 13, 2020. It is now read-only.

[Angular] Routing on AEM route with parameter gives a "Forbidden error" #84

Open
ChetanaAdige opened this issue May 17, 2020 · 16 comments
Assignees

Comments

@ChetanaAdige
Copy link

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

  • AEM 6.4 + SP2
  • Java 1.8
  • Apache Maven (3.3.9 or newer)
  • Node.js v10+
  • npm 6+

Describe the issue
A clear and concise description of what the issue is.

Where in the tutorial are you experiencing an issue?

In Chapter 2 Setting up Angular routes and page resolution

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Using this.router.navigate with queryParams to route to a page in AEM gives a "Forbidden error"
when re-loading that page
the AEMPageDataResolver that is used to return the resource path probably removes the parameters and the page does not render the AEM content

@godanny86
Copy link
Collaborator

hi @ChetanaAdige, to be clear this is not an error directly related to steps in the tutorial?

Instead you are attempting to add a query parameter to an exiting url? Can you post an example of the URL you are trying to create?

Does the route work when navigating through the SPA but fails when trying a full page refresh to the deep link?

@ChetanaAdige
Copy link
Author

ChetanaAdige commented May 18, 2020 via email

@godanny86
Copy link
Collaborator

yes, I would expect a 404, since you are not using a query parameter, but rather an additional path. AEM will interpret that as a brand new request. A query parameter would look like this:

/content/wknd-events/react/home/first-article.html?articleID=A0001

@ChetanaAdige
Copy link
Author

ChetanaAdige commented May 18, 2020 via email

@godanny86
Copy link
Collaborator

Sorry, I don't have a working example. I think you will need to create at a minimum a page in AEM that is a real page i.e /content/wknd-events/agular/home/first-article.html. You may want to use a different resourceType. On the SPA side that page can be "empty" in that it does not render anything and just redirects to the appropriate route based on the query parameter. if no query parameter is present then maybe it just redirects to a 404 or the home page...

@ChetanaAdige
Copy link
Author

ChetanaAdige commented May 18, 2020 via email

@godanny86
Copy link
Collaborator

The course detail page that you describe, is this a real AEM page? Then it should render just fine with or without parameters. "It fails to get the JSON content for the components if the query string parameter is passed" -> I haven't observed this before. The JSON model seems to work fine when adding query parameters...

I can post an example w/ React if that would help...

image

image

@ChetanaAdige
Copy link
Author

ChetanaAdige commented May 18, 2020 via email

@godanny86
Copy link
Collaborator

yes it works in both cases. Is the XHR call to *.model.json broken when you add a query parameter to the url?

@ChetanaAdige
Copy link
Author

ChetanaAdige commented May 18, 2020 via email

@godanny86
Copy link
Collaborator

Then that means /content/wknd-events/react/home/first-article.html doesn't exist as an AEM page. right?

@ChetanaAdige
Copy link
Author

ChetanaAdige commented May 18, 2020 via email

@godanny86
Copy link
Collaborator

On reload it is a full request back to the server :). When you navigate via the SPA the JS, CSS and JSON are already loaded and you never hit the server for these types of artificial routes. You should create a real AEM page and pass query parameters to it...

@ChetanaAdige
Copy link
Author

ChetanaAdige commented May 18, 2020 via email

@godanny86
Copy link
Collaborator

Yes good idea. Pleas post the link to your repo when you have it up

@fusionproj
Copy link

@godanny86 I'm not getting location inside my props object. Can you please share your working example for this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants