-
-
Notifications
You must be signed in to change notification settings - Fork 159
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
feat: support server redirects #491
Conversation
Run & review this pull request in StackBlitz Codeflow. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## v3 #491 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 1
Lines 1 1
=========================================
Hits 1 1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@molefrog, we would greatly appreciate it if you could review this PR. We would very much like to migrate our application from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey! I am so sorry for my long reply. I've added a few comments, could you take a look?
packages/wouter/src/index.js
Outdated
const { to, href = to } = props; | ||
const [, navigate] = useLocation(); | ||
const redirect = useEvent(() => navigate(to || href, props)); | ||
const { ssrContext } = useRouter(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an internal helper hook useLocationFromRouter
that you can use combined with useRouter()
to avoid extra context calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understand this suggestion, there's no need to use location (the result of useLocationFromRouter
) in this instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh never-mind, I see. I can optimize the existing call to useLocation
above since I have a router ref. I pushed the changes.
Released in v3.5.0 |
Add the ability to redirect during SSR. Currently wouter only supports redirect once the app hydrates and the components render client side. Being able to redirect from the server is more efficient (only requires sending a status code/path back), resulting in a better user experience. The response can also be cached by the browser.
Resolves #468