Skip to content

Instantly share code, notes, and snippets.

@jaytaylor
Created July 12, 2017 22:44
Show Gist options
  • Star 29 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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.

@saviomartin
Copy link

Thank you!

@kaikaiikkun
Copy link

Thanks!!!

@coker-deca
Copy link

Thanks

@sugan-ras
Copy link

Thanks!!!

@AmSmart
Copy link

AmSmart commented Sep 21, 2021

Useful, thanks!

@carmageddon888
Copy link

Thanks! 👍

@dogunbound
Copy link

Thanks!!!!

@denymark989
Copy link

Thank you!

@itsKJ
Copy link

itsKJ commented Dec 28, 2021

Thanks 👍

@AlguienSama
Copy link

Thanks!

@onmax
Copy link

onmax commented Jan 20, 2022

Thanks!

@naymello
Copy link

naymello commented Feb 9, 2022

thank you!

@Lyonsmasawa
Copy link

Thanks

@nicolascevallosbUEES
Copy link

TE AMO <4-1

@kan0neego
Copy link

Thanks

@wertzderware
Copy link

Thanks!

@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

@raygyli
Copy link

raygyli commented Jul 5, 2023

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

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