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

AEM SPA Routing Issues with hash and query parameter

  • June 4, 2020
  • 13 replies
  • 10665 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

Level 2
June 6, 2020
Is this Client or Server Side react?
viveksachdeva
Community Advisor
Community Advisor
June 7, 2020
Its Client side..
Level 2
June 7, 2020
So you are using extension less url ? and without looking at your Apache rewriter rule, it is difficult to say whats wrong in the rule
viveksachdeva
Community Advisor
Community Advisor
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)).
Level 2
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
Community Advisor
Community Advisor
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..
Level 2
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
Community Advisor
Community Advisor
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>

 

Level 2
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
Community Advisor
Community Advisor
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