0

How does navigatetoURL works in community Page.We have built a custom lightning component to display list of articles .TO redirect the article to the article page how to does navogatetoURL works in community where the community URL will be /s/article/artilce-urlname

    ({
      getArticles1: function(component) {
      var action = component.get("c.getArticles");

    action.setStorable();

    action.setCallback(this, function(response) {
      var state = response.getState();

      if (state === "SUCCESS") {
        component.set("v.articleview", response.getReturnValue());
      }
    });
    $A.enqueueAction(action);
  }
});


 navigate: function(cmp, event, helper) {
 console.log("test1")
    cmp.find("navService").navigate({

        type: "standard__knowledgeArticlePage",
        attributes: {
            "articleType": "How_To__kav",
            "urlName": "/article/"+{urlName}


            },

        } 
                                   )
    }

<aura:iteration var ="articleview" items="{!v.articleview}">
    <div>
    <p class="astyle"><a class="slds-text-color--default" onclick="{!c.navigate}" >{!articleview.title}</a></p>
</div>
3
  • where you want use navigatetoURL functionality, do you have URl column in your custom lightning component to display list of articles?
    – sdandamud1
    Commented Jun 18, 2019 at 14:39
  • Yes ,we display a list of articles with URl in the lightning component .When the article is clicked it should redirect to the community page by using "onclick" and navigatetoURL in JS controller. @sdandamud1
    – rdredd
    Commented Jun 18, 2019 at 14:46
  • The documentation is pretty straightforward on using the event, where exactly are you stuck?
    – glls
    Commented Jun 18, 2019 at 15:12

1 Answer 1

0

your component must implement the lightning:isUrlAddressable and must to use lightning:navigation i recommended to go through this doc

cmp

<lightning:navigation aura:id="navService"/>

<aura:iteration var ="articleview" items="{!v.articleview}">
    <div>
    <p class="astyle"><a class="slds-text-color--default" onclick="{!c.navigate}" >{!articleview.title}</a></p>
</div>

controller:

({
    navigate: function(cmp, event, helper) {
        cmp.find("navigation").navigate({
            type: "standard__knowledgeArticlePag",
            attributes: {
                "articleType": "c__componentB",
                "urlName": "/article/"+{your url Name}


                },

            } 
        }, true); 
    }
})
2
  • Thanks for looking into it .Tried the above approach but the onclick to redirect to articlepage(xxxx.force.com/community/s/article/urlName) is not working.IS it possible to redirect by Using navigateToURL with articleURLname like in the below example salesforce.stackexchange.com/questions/139965/…
    – rdredd
    Commented Jun 18, 2019 at 17:59
  • i don't think so force:navigateToSObject works in your scenario, it works only for sobject with Id, can you update your question with what you tried so far and what error you getting when is use my solution?
    – sdandamud1
    Commented Jun 18, 2019 at 18:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .