function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
saranya sista 4saranya sista 4 

[navService.navigate is not a function] . could someone please suggest the possible reason for this error .


controller---------
var navService = component.find("navService");
        var pageReference = {
            type: "standard__component",
            attributes: {
                componentName: "c__peDetail"
            },
            state: {
                "projectId": PID
            } 
        };
       console.log(pageReference);
       navService.navigate(pageReference);

defined the variable in cmp -- 
<lightning:navigation aura:id="navService" />
    <aura:attribute name="pageReference" type="Object"/>


 
Raj VakatiRaj Vakati

lightning:navigation is supported only in Lightning Experience, Salesforce Mobile App .. not the standard alone apps (.app)

 
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes">
    <aura:attribute name="url" type="String"/>
    <aura:attribute name="pageReference" type="Object"/>
    <aura:handler name="init" value="{! this }" action="{! c.init }"/>
    <lightning:navigation aura:id="navService"/>
    <a href="{!v.url}">Link</a>
</aura:component>
 
({
    init : function(cmp, event, helper) {
        var navService = cmp.find("navService");
        // Sets the route to /lightning/o/Account/home
        var pageReference = {
            type: 'standard__objectPage',
            attributes: {
                objectApiName: 'Account',
                actionName: 'home'
            }
        };
        cmp.set("v.pageReference", pageReference);
        // Set the URL on the link or use the default if there's an error
        var defaultUrl = "#";
        navService.generateUrl(pageReference)
            .then($A.getCallback(function(url) {
                cmp.set("v.url", url ? url : defaultUrl);
            }), $A.getCallback(function(error) {
                cmp.set("v.url", defaultUrl);
            }));
    }
})

 
saranya sista 4saranya sista 4
I would like to navigate to another component on click of a button . Hence could you post example where page Reference is set in the onClick function.
Raj VakatiRaj Vakati
Refer this link 

https://rajvakati.com/2018/11/13/navigate-to-component-using-lightningnavigation/