🕵️ SicherheitslückenCVE-2026-69116 | xpf0000 FlyEnv up to 4.17.x Html Sanitization injection(17.09.2026 um 04:28 Uhr)
🕵️ SicherheitslückenCVE-2026-69114 | Spacebar Server Message Deletion Handlers permission(17.09.2026 um 04:28 Uhr)
🕵️ SicherheitslückenCVE-2026-18695 | MongoDB Server up to 7.0.39/8.0.28/8.3.7 denial of service(17.09.2026 um 04:28 Uhr)
🕵️ SicherheitslückenCVE-2026-69116 | xpf0000 FlyEnv up to 4.17.x Html Sanitization injection(17.09.2026 um 04:28 Uhr)
🕵️ SicherheitslückenCVE-2026-69114 | Spacebar Server Message Deletion Handlers permission(17.09.2026 um 04:28 Uhr)
🕵️ SicherheitslückenCVE-2026-18695 | MongoDB Server up to 7.0.39/8.0.28/8.3.7 denial of service(17.09.2026 um 04:28 Uhr)
🔧 Programmierung 🕛 vor 2 Jahren 4 Min Lesezeit
0

Tips from open-source: How redirect in Next.js works under the hood

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

In this article, you will learn how redirect in next.js works under the hood by looking at the Next.js source code around redirect functionality.






My approach:




  1. Start from the `import { redirect } from "next/navigation"'

  2. Back trace the redirect function to redirect.ts file

  3. redirect.ts explained

  4. How does throwing an error make the redirect work?

  5. Check redirect.test.ts to understand the full context

  6. redirect-boundary.ts has the redirect functionality



.



But where do I find the next/navigation code? You can find this code in that is has 272 lines of code at the time of writing this article, what we are interested in is the export of “redirect” at the end of the file as shown below. Focus on what you are looking for, don’t let the other code distract you.



, you will find that redirect function is, in fact, from redirect.ts.





Let’s look at the code snippet that throws the error inside






4. How does throwing an error make the redirect work?



Redirect function throws an error that sets the error.digest, but it was not obvious as to how throwing an error makes the redirect work.



I searched long and hard, my initial thoughts were around trying to find that catch block since redirect throws an error. I scoured the server related files but of no use.



I kept at it until it started to make sense when I looked at redirect.test.ts






5. Check redirect.test.ts to understand the full context





It is evident from the test code that getURLFromRedirectError(err) is called. You will find this function






6. redirect-boundary.ts has the redirect functionality



The answer is Next.js redirect uses useRouter hook and depending on redirect type, it either pushes or replaces the url





when the error is thrown from redirect, it is caught by the redirect-boundary and redirect occurs. It is quite fascinating to find that redirect function itself does not do the redirect but rather redirect-boundary inside app-router handles the routing logic.






Conclusion:



I do not know why this API is designed this way but we could use this pattern of throwing an error from your npm package and use a boundary , preferably at the root level, to catch that error and do your thing.



If it wasn’t for me checking the redirect.test.ts code I would not have been able to figure out how the redirect works because I was hoping to find some sort out catch block in the redirect.ts but that is not the case.



Feel free to reach out to me at





  • Vollständiger Original-Artikel
    Den kompletten Beitrag mit allen Details direkt auf dev.to lesen.
    ↗ Original-Artikel auf dev.to lesen
    Wie bewertest du diesen Beitrag?
    1 Klick Feedback
    Teilen mit Netzwerk & Team:

    Community-Analysen & Experten-Meinungen 0

    Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
    Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
    Community Pulse: Relevanz-Einschätzung
    1 Klick Experten-Votum
    🔴 Akute Relevanz 0%
    🟡 In Evaluierung 0%
    🟢 Keine Auswirkung 0%
    Spannende Innovation 0%
    Verwandte Story-Cluster & Quellen (Vektor-KI)
    Port 8095 Engine
    1 Quelle
    Your startup’s next teammate might be an AI agent: Gusto, Insight Partners, and Leland explain what that changes at TechCrunch Disrupt 2026
    1 Quelle
    The streamers are fighting over Halloween
    1 Quelle
    Apple überrascht mit Update auf iOS 27.2
    Ähnliche Beiträge
    🔍 Verwandte News

    Auch interessante Nachrichten Tips from open-source: How redirect in Next.js works under the hood

    Thematisch verwandte Begriffe: Tips, from, opensource, redirect · 6 Treffer

    Laden...

    Beiträge werden geladen ...

    Laden...

    Videos werden geladen ...

    Laden...

    Beiträge werden geladen ...

    Laden...

    Videos werden geladen ...

    Laden...

    Beiträge werden geladen ...

    Laden...

    Videos werden geladen ...

    Laden...

    Beiträge werden geladen ...

    Laden...

    Videos werden geladen ...