2

I have a use case, where I need to navigate from one page to another in community builder along with a parameter. So that I can use this parameter on the new page.

Is this achievable?

I know we can use force:navigateToURL for the navigation. But can we pass the parameter along with it to be used in the next page?

My Calling pgae's component js controller code:

gotoURL : function (component, event, helper) {
    var orderId = "test";
    var navigateEvent = $A.get("e.force:navigateToURL");
            if (navigateEvent) {
                navigateEvent.setParams({
                    "url": '/navigationurl/'+orderId,
                    "isredirect": true
                });
                navigateEvent.fire();
            }
  }

destination page's component's code:

doInit : function(component) {
    var oId = component.get("v.orderId");

    (oId == undefined) {
        var parms = this.getParameters(component);

        oId = parms['orderId'];

        if (oId == null) {
            oId = this.getId(component);
        }
        if (oId != null) {
            component.set("v.orderId", oId);
        }
    }   
}

1 Answer 1

1

You can pass the parameters .Tested with below example

navigate : function(component, event, helper) {

//Find the text value of the component with aura:id set to "address"
var address = component.find("address").get("v.value");

var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
  "url": 'https://www.google.com/maps/place?address=' + address
});
  urlEvent.fire();
}

EDIT

To get last part in your destination component use below code

doInit : function(component) {
   var oId = window.location.href.split("/").pop();
    if (oId != null) {
        component.set("v.orderId", oId);
    }
}   
4
  • Thanks Mohith, This example would work but my use case is i am navigating from one community page to another and i need to use the passed parameter in the destination page. I could not able to access the parameter in the destination page.
    – Pratima
    Aug 15, 2016 at 23:48
  • @pratima can you add code snippet thats failing ?Thank you Aug 15, 2016 at 23:57
  • i just added the code to my original post.
    – Pratima
    Aug 16, 2016 at 0:11
  • @Pratima Just updated the answer .Hope that helps .Thanks Aug 16, 2016 at 0:19

You must log in to answer this question.

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