Skip to content

useLocation() may be used only in the context of a <Router> component. #13272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Vgbire opened this issue Mar 20, 2025 · 2 comments
Closed

useLocation() may be used only in the context of a <Router> component. #13272

Vgbire opened this issue Mar 20, 2025 · 2 comments
Labels

Comments

@Vgbire
Copy link

Vgbire commented Mar 20, 2025

I'm using React Router as a...

library

Reproduction

This library is a third-party library developed based on React router. Please use A for the following explanation.
Replace the description with B for projects that call library A.
When A uses React router version 7.20, B must be the same version as it, not higher than 7.20 and not lower than 7.20. Otherwise, the error 'useLocator () may be used only in the context of acomponent.' will be reported.
Similarly, A also has this issue when using React router version 6.29.0.
I hope that A, as a third-party library, does not need to restrict B from upgrading or downgrading to the same version in order to use it

Link:https://github.com/Vgbire/react-keep-alive
branch: develop
Reproduce steps:

  1. pnpm i
  2. npm run build
  3. npm run start -w example

node version: 16.20.2
react-router: 7.1.5
react-router-dom: 6.29.0
rollup: 4.19.0
I don't know if it repeats with #12785,because I am using Rollup instead of Vite, and the version is not greater than 22.12

System Info

node version: 16.20.2
react-router: 7.1.5
react-router-dom: 6.29.0
rollup: 4.19.0

Used Package Manager

pnpm

Expected Behavior

As a third-party library, does not need to restrict project from upgrading or downgrading to the same version in order to use it

Actual Behavior

The error 'useLocator () may be used only in the context of acomponent.' will be reported.

@Vgbire Vgbire added the bug label Mar 20, 2025
@timdorr
Copy link
Member

timdorr commented Mar 21, 2025

You cannot use two different versions of react-router and react-router-dom. The are incompatible with each other.

@timdorr timdorr closed this as completed Mar 21, 2025
@Vgbire
Copy link
Author

Vgbire commented Mar 26, 2025

@timdorr hi,In the develop branch, I removed all references to react-router-dom, but the problem still persists,can you reopen it ?
Link:https://github.com/Vgbire/react-keep-alive/tree/develop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants