#How to keep <Link /> type-safe in Framework Mode routing?

1 messages · Page 1 of 1 (latest)

trail wasp
#

Hi, I switched from Declarative Mode to Framework Mode and I’m struggling with type-safe routing, specifically with <Link to={}/>.

In Declarative Mode, I used to have a hardcoded object with my paths, for example:

const routes = {
  index: "/",
  dashboard: "/dashboard",
  ...
}

Then whenever I needed a link, I would just do:

<Link to={routes.dashboard} />

Now, because of how paths are declared in routes.ts, I’m not sure what’s the best way to keep my <Link /> type-safe.
Any suggestions on how to approach this?

normal trench
trail wasp
#

That's not what I meant. I just want to have an object with all available paths in the application.

rose osprey
#

where would the keys for that object come from?

trail wasp
#

Maybe not object with keys but typesafe of „to” property

rose osprey
#

Currently that's the href() utility. There may be plans in the works to make the various to props more type-safe, but I'm not an authoritative source on that.