Skip to content

[Bug]: createMemoryRouter is dependant on Web APIs #9796

@Yiin

Description

@Yiin

What version of React Router are you using?

6.6.0

Steps to Reproduce

Create data router using createMemoryRouter(...) and <RouterProvider ...>, use redirect() or navigate() in environment that it neither test env nor a browser.

Expected Behavior

Internal current route should change to the one provided in redirect() or navigate() (as it currently does when using <MemoryRouter>).

Actual Behavior

An error is being thrown:

ReferenceError: window is not defined
    at createClientSideURL (/home/yiin/projects/wicked/node_modules/@remix-run/router/history.ts:570:9)
    at createClientSideRequest (/home/yiin/projects/wicked/node_modules/@remix-run/router/router.ts:2900:13)
    at startNavigation (/home/yiin/projects/wicked/node_modules/@remix-run/router/router.ts:959:19)
    at Object.navigate (/home/yiin/projects/wicked/node_modules/@remix-run/router/router.ts:859:18)

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