Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

106
Views
How to get the current url within a React / Gatsby Class Component

I have used the following to get the url within a function component.

const Header = () => {
  const url = typeof window !== 'undefined' ? window.location.href : '';

But I am looking to do the same for a class component so i can use Ternary.

Any idea how this can be done? I am struggling to find details outside of a functional component.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Thanks @jonrsharpe I was overcomplicating the issue.

I have done what I need with the following:

render() {
    const url = typeof window !== 'undefined' ? window.location.href : '';

    return ( ...

Thank's for your pointers

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!