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.
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?
Solved! Go to Solution.
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
We are doing like similar to https://helpx.adobe.com/experience-manager/kt/sites/using/getting-started-spa-wknd-tutorial-develop/...... 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
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.