Thanks to visit codestin.com
Credit goes to github.com

Skip to content

getRouteApi throws error for all kinds of routes #6528

@SeaRoll

Description

@SeaRoll

Which project does this relate to?

Router

Describe the bug

I use following code:

import { getRouteApi } from '@tanstack/react-router'

const route = getRouteApi('/dashboard/$companyId')

export default function useOptionalCompanyId(): string | undefined {
  try {
    const { companyId } = route.useParams()
    return companyId
  } catch {
    return undefined
  }
}

This methods returns undefined for routes such as:

/dashboard/32a0c53f-0307-44eb-8e60-3be04046d570/editor
/dashboard/32a0c53f-0307-44eb-8e60-3be04046d570

etc.

Your Example Website or App

None

Steps to Reproduce the Bug or Issue

Use latest tanstack version

use the hook

go into a child route

the hook will return undefined

Expected behavior

I expect it to find the companyId

Screenshots or Videos

No response

Platform

  • Router / Start Version: 1.157.16
  • OS: MacOS
  • Browser: chrome
  • Bundler: vite
  • Bundler Version: latest

Additional context

Seems like the routeTree.gen.ts is updated with the new version for @tanstack/router-plugin it works in 1.150.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions