Skip to content

<Link/> cannot be rendered outside <Router/> but doesn't tell me about that #12989

Closed as not planned
@kettanaito

Description

@kettanaito

I'm using React Router as a...

library

Reproduction

import { Link } from 'react-router'

<div>
  <Link to="/cart">Go to Cart</Link>
</div>

Sorry for not providing more but it's not necessary, really. The <Link /> component doesn't seem to have the same check as React Router hooks, resulting in a degrading DX.

System Info

I believe this is irrelevant.

Used Package Manager

npm

Expected Behavior

I expect this unintentionally incorrect usage to throw the same error as I get when using React Router hooks without the <Router /> context:

Error: <Link> may be used only in the context of a <Router> component.

This will be a more meaningful error message and will help me figure out what I'm doing wrong, as opposed to the internal "cannot read from context because context doesn't exist", which doesn't tell me much.

Actual Behavior

The following, user-unfriendly error is being thrown:

Cannot destructure property 'basename' of 'React10.useContext(...)' as it is null.

I know this error has been raised before in #11237 and #10867, none of which were actually solved for developers also due to this error being semi-cryptic.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions