docs: add info about location.href
See original GitHub issueSummary
- add section about
location.href
is not available in SSR
Motivation
some mistakes are coming from using location.href
in server side rendering - but there is no place in docs where is a hint about this
-const href = location.href
+const href = `${siteUrl}${pathname}`
References
https://css-tricks.com/how-to-the-get-current-page-url-in-gatsby/#article-header-id-4
Steps to resolve this issue
Docs
maybe placing infos here:
- https://www.gatsbyjs.org/docs/troubleshooting-common-errors/
- https://www.gatsbyjs.org/docs/location-data-from-props/
Draft the doc
- Write the doc, following the format listed in these resources:
- Overview on contributing to documentation
- Docs Templates
- Example of a similar article
- Add the article to the docs sidebar under the [parent doc] section.
Open a pull request
- Open a pull request with your work including the words “closes #[this issue’s number]” in the pull request description
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Work with links & bookmarks - Google Docs Editors Help
Add a link · Open a file in the Google Docs, Sheets, or Slides app. · Docs: Tap Edit · Highlight text or...
Read more >location.href - Web APIs | MDN
The href property of the Location interface is a stringifier that returns a string containing the whole URL, and allows the href to...
Read more >Location href Property - W3Schools
The location.href property sets or returns the entire URL of the current page. Syntax. Return the href property: location.href.
Read more >pass post data with window.location.href - Stack Overflow
What you have to do is to set up a form tag with data fields in it, set the action attribute of the...
Read more >Localized Versions of your Pages | Google Search Central
Add <link rel="alternate" hreflang=" lang_code "... > elements to your page header to tell Google all of the language and region variants of...
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 Free
Top 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
On top of documention, we can make trying to access
location.href
to throw error in code (which would contain link to appropriate docs. Alternatively we could maybe construct.href
for SSR? But I feel like constructing it ourselves might just hide some problems and introduce even more problems (subtle, and hard to debug)To provide an error message in this situation, there needs to be a change to reach/router. I’ve submitted an issue and a PR on reach that should fix it.