AEM SPA Routing Issues with hash and query parameter | Community
Skip to main content
viveksachdeva
New Participant
June 4, 2020
Solved

AEM SPA Routing Issues with hash and query parameter

  • June 4, 2020
  • 13 replies
  • 10645 views

Hey guys,

 

We are using AEM with React and having trouble with SPA Routing. We are facing an intermittent issue when the Link contains # or ?

Page data is available using .model.json on the page URI but sometimes when we have # and ?, model.json is added after full URL rather than just path and hence it fails.

And it happens when on dispatcher only when we dont have .html in the URL.

E.g:

Lets say a React Link points to /en/mypage?cid=campaign

I expect data call for this to be  /en/mypage.model.json but sometimes it is sent as /en/mypage?cid=campaign.model.json

 

This logic is abstracted in the node module and hence difficult to check. Anyone else faced similar issue?

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by dzmitryk7401781

We've prepared patch to fix it: https://github.com/adobe/aem-spa-page-model-manager/pull/54 

13 replies

dzmitryk7401781Accepted solution
New Participant
March 22, 2021
kautuk_sahni
Employee
March 23, 2021
@dzmitryk7401781, thank you for sharing the solution with community. Keep doing the great work. Looking forward to see you more in the AEM community.
Kautuk Sahni
New Participant
March 5, 2021

We also have the same issue appearing, right after we started to rewrite URLs removing `.html` bit in a page path.

 

Looks to me that URL parsing code in the routing library contains a bug for the case of absent page extension and should be fixed.

viveksachdeva
New Participant
March 21, 2021
Yeah. we had to change those links to normal links rather than React link..
Nikhil-Kumar
New Participant
August 24, 2020

@viveksachdeva 

Try playing around with the dipatcher re-write rules if it helps.

We guys also implemented similar thing but didn't faced such issue.

viveksachdeva
New Participant
August 25, 2020
The URL modification happens at client side before it reaches Dispatcher. For "#" in the URL, we were facing this issue consistently but query params, it was intermittent.
viveksachdeva
New Participant
June 7, 2020

We are doing like similar to https://helpx.adobe.com/experience-manager/kt/sites/using/getting-started-spa-wknd-tutorial-develop/react/chapter-3.html... Does it really matter how we populate the URL.. It is just a JSX variable and it is populated on what author puts in the component. When I say automatically, I mean whenever we pass a URL to React Link, AEM automatically makes a call to model.json of the link specified in to attribute.

 

There isnt anything in componentDidMount.. We just get props in mapped JS for the components and thats what we are using in React Link

 

New Participant
June 7, 2020
that code is just <a> in React, but how React component is populating myurl? there must be some React component State properties which is read , check that code, also when you say autometically, there must be some code on componentDidMount() which triggers async call. Sorry without your further code I cannot help you.
viveksachdeva
New Participant
June 7, 2020

It is happening while routing from one page to another.. cq:pagemodel_root_url always has root page URL and not current page URL. And we are not using custom code to load page model json. Its just a Link tag with a URL and that automatically calls model.json internally

<Link to={myurl}>
Label
</Link>

 

New Participant
June 7, 2020
this issue comes when first time page load or after page is loaded then when you navigate between links? It seems you have custom code to call model.json on every link click, it could be issue with react component state is not updated correctly, so if you post your code then will be better to upderstand
viveksachdeva
New Participant
June 7, 2020
That part is maintained in header and header doesnt change when we navigate between the pages. and it points only to root page which is fine..
New Participant
June 7, 2020
Understood, are you using Adobe SDK or own to call model? if Adobe SDK then can you check what is the value of cq:pagemodel_root_url when you have this error, ideally it should have yourUrl.model.json and then React code reads it from there
viveksachdeva
New Participant
June 7, 2020
Yes I am using extensionless URLs. Its not really an issue with Apache rewrite because the model.json request that is generated from the browser itself is incorrect(adding mode.json after full URL rather than just the path)).