Get current URL in custom component
See original GitHub issueEach of my blog posts contains the markdown…
See a typo? You can fix it by editing [this file](https://github.com/bender2k14/tyson-williams-blog/blob/master/src/markdown/2020-07-15_naming_is_impossibly_hard.md) and then sending me a [pull request](https://github.com/bender2k14/tyson-williams-blog/compare).
…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.
Input:
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>
</ul>
Output:
- 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:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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.