Skip to content

navigate('relative') in layout appends to parent route instead of layout's child #14035

@hsab

Description

@hsab

Reproduction

--

System Info

System:
    OS: macOS 15.5
    CPU: (8) arm64 Apple M1 Pro
    Memory: 91.27 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.13.0 - ~/.nvm/versions/node/v22.13.0/bin/node
    npm: 10.9.2 - ~/.nvm/versions/node/v22.13.0/bin/npm
    pnpm: 9.15.4 - ~/.nvm/versions/node/v22.13.0/bin/pnpm
  Browsers:
    Chrome: 138.0.7204.158
    Chrome Canary: 140.0.7309.0
    Safari: 18.5
  npmPackages:
    @react-router/dev: ^7.6.2 => 7.6.2
    @react-router/node: ^7.6.2 => 7.6.2
    @react-router/serve: ^7.6.2 => 7.6.2
    react-router: ^7.6.2 => 7.6.2
    vite: 6.3.4 => 6.3.4

Used Package Manager

pnpm

Expected Behavior

I have the following route structure:

const pages = [
  layout('routes/pages/MainLayout.tsx', [
    index('routes/pages/home/ProjectsPage.tsx'),
    layout('routes/pages/flow/FlowLayout.tsx', [
      route('flow/:slug', 'routes/pages/flow/FlowPage.tsx', [
        route('settings', 'routes/pages/settings/SettingsPage.tsx')
      ])
    ])
  ])
];

When relative navigate('settings') is used in FlowLayout or any component that is imported in FlowLayout, the resolved path is always relative to the index.

For example, invoking navigate('settings') via FlowLayout, when the current path is https://acme.com/flow/abc-efg results in https://acme.com/settings.

My expectation is that relative use of navigate should be resolved in relation to window.location.href, resulting in https://acme.com/flow/abc-efg/settings, even when invoked from FlowLayout.

I know the behavior is essentially related to resolvedPath, but is this the expected behavior and mental model?

Actual Behavior

Relative use of navigate('path') should be resolved in relation to window.location.href

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