Can lightning:navigation be used in Communities
lightning:navigation is not supported in communities .Take a look at Summer18 release notes here that clearly mentions below
These resources aren’t supported in other containers, such as Lightning Components for Visualforce, Lightning Out, or Communities. This is true even if you access these containers inside Lightning Experience or the Salesforce mobile app.
Update:
With Recent releases it is now supported in lightning communities as well .
There's been an update for this since the best answer was posted and it's now possible to navigate around at your heart's content.
Here's how:
On the component:
<!-- exampleComponent.cmp -->
<aura:component implements="forceCommunity:availableForAllPageTypes" access="global" >
<lightning:navigation aura:id="navService"/>
<!-- Your content here -->
<lightning:button label="Navigate To Page" variant="Neutral" onclick="{!c.completeOrder}" />
</aura:component>
In the controller:
({
navToPage : function (component, event, helper) {
// gets the <lightning:navigation> tag on the component
let navService = component.find("navService");
// Sets the route to [Org url]/[Community uri]/[pageName]
let pageReference = {
type: "comm__namedPage", // community page. See https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_navigation_page_definitions.htm
attributes: {
pageName: 'home' // pageName must be lower case
}
}
navService.navigate(pageReference);
}
})
And that's it!
If you'd prefer, there are more options including generating the url on init and saving it in an attribute to use later, or writing the controller code in the helper file instead of directly in the controller, which allows you to more cleanly input a pageName without a giant chunk of code - especially if you want to reuse it.
For more info, see the below links:
lightning:navigation tag:
https://developer.salesforce.com/docs/component-library/bundle/lightning:navigation/documentation
Page Reference Types:
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_navigation_page_definitions.htm
Cheers Guys! Happy coding!
Dunks