RFC: Simplification of Pathname Navigation API in TanStack Router #1277
Replies: 2 comments
-
I'm wondering about suggestions. I'm not sure how good suggestions for template literal types are now. For example:
Needs to be replaced with:
So I assume this is a type checker error. Which will work fine. How does the ide help the dev reach this conclusion as I'm not sure if suggestions work for this. A |
Beta Was this translation helpful? Give feedback.
-
Just two things on my side:
const postId = '123'
<Link
// oh no! my prettier broke stuff to a new line
to={`/posts${
postId
}/edit`}
// would this bork my type-inference now?
/>
Objectively my only real concern is (1.), and would we be opening up the Router to weird string interpolation stuff that we don't really have any control over. My second point was just a use-case I saw that Router made possible, but is not really any cause for concern. |
Beta Was this translation helpful? Give feedback.
-
Summary
This RFC proposes a simplification of the
pathname
navigation API within the TanStack Router to enhance developer experience and type safety. The proposed changes aim to streamline the API by eliminating the need for separateto
andparams
in navigation, instead supporting direct interpolation within theto
string.Motivation
The current API, while designed for type safety and ease of use through autocomplete suggestions and strict dynamic path parameters, has been identified as somewhat clunky and limiting. The complexity arises especially when dealing with dynamic path parameters, leading to a less intuitive API.
Proposal
The new API version will require only the
to
field for navigation, supporting dynamic path interpolation directly. This approach will retain autocomplete functionality and type safety while making the API more straightforward to use. The main features of the proposed API include:to
string, reducing the API's complexity./posts/$postId/
) is detected, the system will enforce type safety by requiring the interpolation of actual values or variables.Example Usage
Upon typing
/post
, a developer would see suggestions like:/posts
/posts/$postId/
/posts/$postId/edit
Selecting
/posts/$postId/
would then prompt the developer to interpolate a value for$postId
, ensuring type safety.Breaking Changes
Continued Support for
params
APIThe
params
API will still be available as a method for updating the current route's parameters. This ensures backward compatibility and flexibility for cases where directto
interpolation may not be used.Rationale
This proposal stems from a need to simplify the TanStack Router's navigation API, making it more intuitive and less error-prone. By enabling direct interpolation within the
to
string and removing less-desirable patterns like parse/serialize for path parameters, we can offer a more streamlined and developer-friendly API.Implementation
The proposed changes will require updates to the TanStack Router's core navigation logic to support direct path interpolation and enforce type safety dynamically. Additionally, the autocomplete suggestion mechanism will be enhanced to provide more relevant templates based on the developer's input.
Open Questions
Feedback
Community feedback is crucial to refining and validating this proposal. We welcome comments, concerns, and suggestions from all stakeholders to ensure that the new API meets the needs of the broader developer community.
This RFC is open for discussion and feedback. Please share your thoughts and suggestions to help shape the future of pathname navigation in the TanStack Router.
Beta Was this translation helpful? Give feedback.
All reactions