Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react-router): navigate if redirect is thrown in component #3107

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

schiller-manuel
Copy link
Contributor

No description provided.

Copy link

nx-cloud bot commented Jan 3, 2025

View your CI Pipeline Execution ↗ for commit b0ae919.

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 4m 35s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1m View ↗

☁️ Nx Cloud last updated this comment at 2025-01-03 23:48:46 UTC

Copy link

pkg-pr-new bot commented Jan 3, 2025

Open in Stackblitz

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/@tanstack/arktype-adapter@3107

@tanstack/create-router

npm i https://pkg.pr.new/@tanstack/create-router@3107

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@3107

@tanstack/create-start

npm i https://pkg.pr.new/@tanstack/create-start@3107

@tanstack/history

npm i https://pkg.pr.new/@tanstack/history@3107

@tanstack/react-router

npm i https://pkg.pr.new/@tanstack/react-router@3107

@tanstack/react-cross-context

npm i https://pkg.pr.new/@tanstack/react-cross-context@3107

@tanstack/react-router-with-query

npm i https://pkg.pr.new/@tanstack/react-router-with-query@3107

@tanstack/router-cli

npm i https://pkg.pr.new/@tanstack/router-cli@3107

@tanstack/router-devtools

npm i https://pkg.pr.new/@tanstack/router-devtools@3107

@tanstack/router-generator

npm i https://pkg.pr.new/@tanstack/router-generator@3107

@tanstack/router-plugin

npm i https://pkg.pr.new/@tanstack/router-plugin@3107

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/@tanstack/router-vite-plugin@3107

@tanstack/start

npm i https://pkg.pr.new/@tanstack/start@3107

@tanstack/start-vite-plugin

npm i https://pkg.pr.new/@tanstack/start-vite-plugin@3107

@tanstack/valibot-adapter

npm i https://pkg.pr.new/@tanstack/valibot-adapter@3107

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/@tanstack/virtual-file-routes@3107

@tanstack/zod-adapter

npm i https://pkg.pr.new/@tanstack/zod-adapter@3107

commit: b0ae919

@schiller-manuel schiller-manuel force-pushed the navigate-redirect branch 2 times, most recently from 5d0ea08 to 1a4d32f Compare January 3, 2025 23:09
_fromLocation: router.state.location,
})
return (
<Navigate {...redirect} replace={true} ignoreBlocker={true} />
Copy link
Member

Choose a reason for hiding this comment

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

What's the rationale for setting replace=true here? Is this something that's required to make it work?
Or is it purely for allowing the user to go from 1 to -1 in a single back button click when considering the user being at position 1 in [ -1 , 0 , 1 ]?

Asking, because if this is not something required on our side to make it functional at runtime, then perhaps, we shouldn't be enforcing replace=true on our side forcing a history replacement. Maybe this should be something the user should opt-in to?

@@ -252,6 +252,84 @@ describe('redirect', () => {
expect(await screen.findByText('Final')).toBeInTheDocument()
expect(window.location.pathname).toBe('/final')
})

test('when `redirect` is thrown in route component', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

I think we should test the back button behaviour here since it'd likely be one of the few buttons that'd be front of mind for the end-user to consider immediately hitting next.

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.

2 participants