3

I want to store the current URL in a hidden field on a form in a lightning component.

The input field on the component:

<ui:inputText aura:id="articleURL"value="{!c.getURL}"/>

Client-siide controller:

getURL : function(cmp, event){
                var articleURL = window.location.pathname;
            }

I recieve an error that says the value: replace is not allowed in this context. Any ideas how I should be handling this?

1 Answer 1

3

Aura/lightning is intended to create single page applications. I am not sure how far you could go by storing URL, having said that I found a way to do this

Note: I tested this in my browser, not on SF1 app.

Component:

<aura:component >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <ui:inputText aura:id="articleURL"/>
</aura:component>

Contorller:

({
        doInit: function(cmp) {
        cmp.find("articleURL").set("v.value", window.location.pathname);
    }
})

Output:

enter image description here

2
  • Rao, you are the best.
    – Allen Mann
    Nov 5, 2015 at 18:12
  • lol @AllenMann thanks for the compliment. I am hunting around to see how people are using lightning and answering mostly lightning based questions hence i get to play around a bit more. I am sure you will be way better than me in no time :)
    – Rao
    Nov 5, 2015 at 18:14

You must log in to answer this question.

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