T
TanStack10mo ago
other-emerald

Obtain the pathname of a route outside of React?

Hi there, if i need to construct an array of objects(like an AST) to display a sidebar tree, what is the correct way of accessing the route string for typesafe to be passed in the sidebar definition? I've tried by importing the Route from each createRoute defined but somehow the "to" property comes undefined, in the console looks like Js Proxy Here is a screenshot of the tree object
No description
10 Replies
other-emerald
other-emeraldOP10mo ago
Here is a definition of the route for example
No description
complex-teal
complex-teal10mo ago
AST as in abstract syntax tree? the undefined problem might come from automatic code splitting. is this enabled?
other-emerald
other-emeraldOP10mo ago
Yes as abstract tree not sure if should be the right words. First project using “start” trying to migrate an existing project from next. I’ll check the docs again to see if I enabled code splitting. I am using virtual routes
complex-teal
complex-teal10mo ago
ok in start autocode splitting is enabled , which during building manipulates routes so the separate export will not work try importing the "Route as..."
other-emerald
other-emeraldOP10mo ago
Mmm. Ok. You’re probably right coz I am damn sure it was working before I decided to do double export
complex-teal
complex-teal10mo ago
I would generally recommend not importing the route and instead using string literals importing the routes can lead to circular dependencies
complex-teal
complex-teal10mo ago
Link options | TanStack Router React Docs
linkOptions is a function which type checks an object literal with the intention of being used for Link, navigate or redirect linkOptions props The linkOptions accepts the following option: ...props T...
other-emerald
other-emeraldOP10mo ago
doesn't work still shows as undefined, but the console shows "to" property as getter, there is "_to" also i imagine that's internal I'll try the linkOptions
complex-teal
complex-teal10mo ago
it should be defined, but only after Router was initialized so make sure to execute that code after createRouter
other-emerald
other-emeraldOP10mo ago
Ok, so the definition would have to be a function Is working now....thanks for the guidance 👍

Did you find this page helpful?