Skip to content

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

@Vgbire

Description

@Vgbire

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions