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

Remove outdated & possibly confusing statement about redirects #33224

Merged
merged 2 commits into from
Jan 12, 2022
Merged

Remove outdated & possibly confusing statement about redirects #33224

merged 2 commits into from
Jan 12, 2022

Conversation

kachkaev
Copy link
Contributor

@kachkaev kachkaev commented Jan 12, 2022

Documentation / Examples

  • Make sure the linting passes by running yarn lint

The statement I have removed may be misleading. A colleague of mine has interpreted it as ‘we need to create a custom page or <Link href="/redirect-path" /> won’t work on the client’. I just ran npx create-next-app --example redirects redirects-app and confirmed that this was not necessary.

So saying that redirects “do not affect client-side routing” is probably wrong. They do and they do it the right way.

Copy link
Member

@ijjk ijjk left a comment

Choose a reason for hiding this comment

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

Hi, so this statement is still accurate in that we don't send the redirects to the client to use them during resolving client-side navigations. The case where redirects can fail with next/link is when you have a redirect that should take priority over a client-side route like a rewrite or a page e.g. if we have a redirect { source: '/first', destination: '/somewhere' } and then a page pages/[slug].js then next/link will navigate to [slug] since it matches.

If a page or rewrite is not matched client-side then Next.js will do a hard navigation which will then trigger the redirect to apply server-side.

Maybe we can tweak this note to make the above scenario where they won't take affect more clear

@kachkaev
Copy link
Contributor Author

kachkaev commented Jan 12, 2022

Thanks @ijjk! Yeah looks like the situation is more sophisticated than I imagined. So I believe that the redirects example works because there are no catch-all routes that would clash with redirects in next.config.js.

Perhaps, the statement I have removed can be replaced with the Caveats section? It does not have to be that high in the doc because not everyone will encounter redirect shadowing. What we want to avoid though is unnecessarily created pages that duplicate what next.config.jsredirects already do.

Happy for you to ditch my PR in favour of a more detailed explanation. Alternatively, I’m also happy to help with the markdown but I’m not sure if my understanding is deep enough to pick the right words.

Copy link
Member

@timneutkens timneutkens left a comment

Choose a reason for hiding this comment

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

This is outdated indeed!

@kodiakhq kodiakhq bot merged commit 6c8808e into vercel:canary Jan 12, 2022
@kachkaev kachkaev deleted the patch-2 branch January 12, 2022 17:38
@vercel vercel locked as resolved and limited conversation to collaborators Feb 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants