Skip to content

Instantly share code, notes, and snippets.

@jaytaylor
Created July 12, 2017 22:44
Show Gist options
  • Save jaytaylor/b14716671ae6a8cd057bd6d849670238 to your computer and use it in GitHub Desktop.
Save jaytaylor/b14716671ae6a8cd057bd6d849670238 to your computer and use it in GitHub Desktop.
Solution for "Unexpected use of 'location'" React error.
React: Unexpected use of 'location';

Solution: Use window.location instead of bare location.

@tNita
Copy link

tNita commented Sep 27, 2022

Thanks!

@gopikanair018
Copy link

Thank you!

@thepenguinmaster
Copy link

thepenguinmaster commented Oct 30, 2022

Thank you! 🍵

@argf013
Copy link

argf013 commented Nov 28, 2022

thanks

@VijoPlays
Copy link

That's how I like my solutions: Quick, to the point and most importantly: Working.

Thanks, lmao!

@Mohammadnoorcse
Copy link

import {useLocation} from "react-router-dom"
const location = useLocation();
const redirect = location.search ? location.search.split("=")[1] : "/"; can not working .... using react-router-dom

please help me.....

@darkwoodbeats
Copy link

this works, thanks!

@beachstrider
Copy link

Thanks!

@CarolineFang1998
Copy link

Thanks

@R4YGUL4RiZ3
Copy link

Thanks!

@pratik9818
Copy link

why we have to access location object through window even window is global object , can anyone answer it ,it will help me and other as well
--thank you.

@hossein-ketabi
Copy link

Thanks

@luuksg12
Copy link

luuksg12 commented Sep 4, 2023

Thanks

@563rajesh
Copy link

thanks

@ekebobrown
Copy link

why we have to access location object through window even window is global object , can anyone answer it ,it will help me and other as well --thank you.

Please did you get a response to this anywhere?

@CaioLuColaco
Copy link

thanks

@stefaniafrolovafrolov
Copy link

Спасибо) Это сработало) Ранее я window с location не использовал.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment