#Keep id when navigate between routes

4 messages · Page 1 of 1 (latest)

odd elk
#

Hello I would like to know how I can navigate from a route to different one keeping the id.

For example I have a list with items and when I select an item and I would like to go from:

route1/{id1}
route1/{id2}

but the route it's on sidebar navigation and and will be on all the routes

the code below it's working but I've got type errors. How I can solve this issue?

    navigate({
      params: { farmId },
      search: router.location.search,
    })```

```tsx
Object literal may only specify known properties, and 'farmId' does not exist in type 'ParamsReducerFn<RouterCore<Route<Register, any, "/", "/", string, "__root__", undefined, {}, {}, AnyContext, AnyContext, {}, undefined, RootRouteChildren, FileRouteTypes, unknown, unknown, undefined>, "never", false, RouterHistory, Record<...>>, "PATH", string, string | undefined>'.```

```tsx
Type '{ search?: string | undefined; status?: string | undefined; countryCode?: string | null | undefined; latitude?: number | null | undefined; longitude?: number | null | undefined; sbi?: number | ... 1 more ... | undefined; parcelId?: string | undefined; species?: string | undefined; }' is not assignable to type 'true | ParamsReducerFn<RouterCore<Route<Register, any, "/", "/", string, "__root__", undefined, {}, {}, AnyContext, AnyContext, {}, undefined, RootRouteChildren, FileRouteTypes, unknown, unknown, undefined>, "never", false, RouterHistory, Record<...>>, "SEARCH", string, string | undefined> | undefined'.```
outer sierra
odd elk
# outer sierra please provide a complete minimal reproducer project, fork this stackblitz proje...

hello, I've created a demo here

https://stackblitz.com/edit/tanstack-router-unh8c7gq?file=src%2Froutes%2F__root.tsx,src%2Fcomponents%2FSelectItems.tsx,src%2Froutes%2Fdashboard.expenses.%24invoiceId.tsx,src%2Froutes%2Fdashboard.route.tsx,src%2Fcomponents%2FInvoiceFields.tsx&preset=node

I've added a select globally and for example if I'm on invoice/id and I click expenses I would like to keep the id and navigate to /expenses/id

but the expenses/id can be any route which has $invoiceId

odd elk
#

this it's the fix in my case to:"."

    navigate({
      to:".",
      params: { farmId },
      search: router.location.search,
    })```