Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get current URL in custom component

See original GitHub issue

Each of my blog posts contains the markdown…

See a typo? You can fix it by editing [this file]( and then sending me a [pull request](

…except that 2020-07-15_naming_is_impossibly_hard is unique to each post.

I want to create a custom component to automate this work, but I don’t know where to get that string. Here is what I have tried.


return <ul>
         <li>document.location.href is {document.location.href}</li>
         <li>document.location.pathname is {document.location.pathname}</li>
         <li>window.location.href is {window.location.href}</li>
         <li>window.location.pathname is {window.location.pathname}</li>
         <li>document.URL is {document.URL}</li>
         <li>document.baseURI is {document.baseURI}</li>


- document.location.href is about:blank
- document.location.pathname is blank
- window.location.href is about:blank
- window.location.pathname is blank
- document.URL is about:blank
- document.baseURI is about:blank

Am I doing this wrong or is CODEDOC not setting those values (or both!)?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

loreanvictorcommented, Jul 20, 2020

Actually, on article cards, the information is not necessarily available. Imagine you have two articles referencing each other using Article cards, both either being built for the first time or their hero image / title / etc changing in the current build. Trying to resolve this information on the server side would only be possible by a deferred two-pass rendering which is too much added complexity for minor performance gain.

TysonMNcommented, Jul 20, 2020

I am still only holding back to come across a use-case that would need the performance, to ensure that we add a method of providing global config to components in a manner suitable for actual use-cases.

Waiting for more use cases is a very good idea. This might be another use case.

I noticed that all the five article cards on my home page take a bit of time to fetch their data on the client. The URL in each article card is to another page in the same site…built by CODEDOC “at the same time” as the current page. In theory, this information is available on the server.

Maybe the article card could be optimized with behavior that depends on the provided URL. If the URL is to another page in the same site built by CODEDOC “at the same time”, then all the desired information is collected on the server. Otherwise, the URL is to a page on a different site, and the desired information is obtained on the client using the current behavior of the article card.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get current page URL in controller whlile creating custom ...
You will have the whole URL in sPageURL variable. You can pas it to your apex class method using an action: var action...
Read more >
Read the current full URL with React? - Stack Overflow
As said above, the easiest way to get the URL is via window.location.href . we can then extract parts of the URL through...
Read more >
Current Page URL - Salesforce Developer Community
I am writing a custom apex page which call a custom component. ... but i am interested to get the rest of the...
Read more >
How to get the current URL and pathname in React
The simplest way to get the current URL and pathname in React is using a browser's window object. const currentURL = window.location.href ...
Read more >
How To Get The Current URL With JavaScript - W3Schools
Current URL. Use window.location.href to get the current URL address: ... innerHTML = "The full URL of this page is:<br>" + window.location.href;.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found