[SalesForce] Lightning Community (Napili) URL parameters

We have lightning community in our Salesforce org, and there are multiple custom pages created. Often we pass parameters through URL.
Examples would be:

  • https://<_community-url>/s/my-orders?active=closed
  • https://<_community-url>/s/my-orders?active=current

This approach works but comes with an issue, that I believe might be bug or something overlooked when the Community Router was designed.

Normally links to subpages of Community work with routes in a way, that whole SPA is not reloaded each time you navigate. Instead, required components are fetched and subpage is rendered. This is of course much faster than loading whole SPA again. And here comes the issue. If I click link /s/my-orders everything is fine. SPA Routing works like a charm. Unfortunately when I click /s/my-orders?active=closed whole page is reloaded as if you pressed F5.

Do you know if there is a way to pass parameters when navigating to different page of community, preventing SPA reload?

Best Answer

Try force:navigateToURL event (docs).

In your component controller handle click event like this:

var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
   "url": "/my-orders?active=closed"
});
urlEvent.fire();
Related Topic