Skip to content

Conversation

@chorobin
Copy link
Contributor

We can infer trailingSlashes from the router and use it to enforce the to prop when navigating.

trailingSlashes currently has three options: always | never | preserve.

always - we always have a trailing slash on leaves autocompleted with to. Branches are not affected in from as you might want a loose match on this for any leaves under a branch instead of an index route.

never - we never have a trailing slash on leaves when autocompleted on to. from does not change as mentioned in always

preserve - to autocompletes to include both trailing slash or without in the union. It can be either.

- always will always add trailing slashes to the leaves of `to` prop
- never will always remove trailing slashes from the leaves of `to` prop
- preserve will allow both paths with or without slashes
@nx-cloud
Copy link

nx-cloud bot commented Apr 22, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 3cead7f. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 2 targets

Sent with 💌 from NxCloud.

@chorobin
Copy link
Contributor Author

Don't merge yet. I want to add more type tests to cover over parts that could have regressed

: 'fullSearchSchema',
> = PostProcessParams<
RouteByPath<TRouteTree, TFrom>['types'][TFromRouteType],
RouteByPath<TRouter['routeTree'], TFrom>['types'][TParamVariant extends 'PATH'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a typescript performance optimization (moving out of the type params)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. I thought about it quite a bit. I now need access to the options on the router. Which would be fine with RegisteredRouter if it weren't for the type tests. Module augmentation is awkward with type tests. It's easier to mock it out if the whole router is a type parameter


test('when navigating to the root', () => {
expectTypeOf(Link<RouteTree, string, '/'>)
type hi = DefaultRouter['options']['trailingSlash']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Ye. I'm changing the type tests atm

@chorobin
Copy link
Contributor Author

Should be ok to merge when approved

@schiller-manuel schiller-manuel merged commit 167ac74 into main Apr 25, 2024
@schiller-manuel schiller-manuel deleted the type-level-trailing-slashes branch April 25, 2024 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants