Astro Advanced Routing

Astro 고급 라우팅

Astro 7 lets a fetch entrypoint compose authentication, API forwarding, and page rendering order.

···
html
<section class="stage"><div class="heading">ADVANCED ROUTING <span class="hint">request pipeline</span></div><div class="pipeline-steps"><div class="request-chip">REQUEST</div><div class="step-chip">AUTH</div><div class="step-chip">ACTIONS</div><div class="step-chip">PAGE</div></div><div class="route-result" id="route-result">Request enters src/fetch.ts</div><div class="caption">Compose stages before the page responds</div></section>
css
.stage{width:min(94vw,780px);height:min(88vh,322px);padding:clamp(12px,3vmin,20px);border:1px solid var(--line);border-radius:16px;background:var(--surface);box-shadow:0 12px 36px #0001;display:flex;flex-direction:column;gap:clamp(7px,2vmin,14px);font:500 clamp(12px,3.5vmin,17px)/1.3 var(--font-sans,system-ui,sans-serif);overflow:hidden}.heading{display:flex;justify-content:space-between;align-items:center;gap:8px;font-weight:750;color:var(--accent)}.hint{color:var(--muted);font-size:clamp(12px,3.2vmin,14px);font-weight:500}.caption{margin-top:auto;color:var(--muted);font-size:clamp(12px,3.2vmin,14px)}.row{display:flex;gap:clamp(5px,1.5vmin,12px);align-items:center}.tile{padding:clamp(6px,1.8vmin,13px);border:1px solid var(--line);border-radius:9px;background:var(--bg);text-align:center;min-width:0}.arrow{color:var(--accent);font-weight:800}.stage [data-on]{transition:background .3s,border-color .3s,opacity .3s,transform .3s}.stage .on{border-color:var(--accent);background:color-mix(in srgb,var(--accent) 14%,var(--surface));color:var(--accent)}.pipeline-steps{flex:1;display:flex;align-items:center;justify-content:center;gap:clamp(3px,1.2vmin,10px)}.request-chip,.step-chip{flex:1;max-width:150px;min-width:0;border:1px solid var(--line);border-radius:8px;padding:clamp(5px,1.5vmin,10px) 2px;text-align:center;background:var(--bg);font-weight:700;font-size:clamp(12px,3vmin,15px)}.request-chip{color:var(--accent)}.step-chip.current{border-color:var(--accent);background:color-mix(in srgb,var(--accent) 18%,var(--surface))}.route-result{text-align:center;color:var(--accent-2);font-weight:700;font-size:clamp(12px,3vmin,15px)}.stage small,.stage button,.stage .cards b,.stage .phase b,.stage .pair b,.stage .tree-mini b{font-size:clamp(12px,3.2vmin,14px)!important}
js
const chips=[...document.querySelectorAll(".step-chip")],result=document.getElementById("route-result"),labels=["Auth checks the request","Actions run after auth","Page renders the response"];let step=0;function tick(){chips.forEach((chip,i)=>chip.classList.toggle("current",i===step));result.textContent=labels[step];step=(step+1)%3}tick();const timer=setInterval(tick,900);document.querySelector(".stage").addEventListener("pointerdown",()=>{clearInterval(timer);tick()})

Astro 7 Advanced Routing accepts a request in src/fetch.ts, then passes it to Astro or returns another response. An app can compose authentication, Actions, middleware, and page rendering in its chosen order.

Simple file routing needs no custom entrypoint. When changing the pipeline, test boundaries such as whether authentication runs before Actions.

When to use

Use it when an Astro app needs explicit control over the order of page and API request stages.

Open as page ↗