Next Js: Parallel routes
So I was working on a project in Next.js 15.
I had two components, each fetching data from different APIs.
Everything was smoothโฆ until one of the APIs stopped responding.
Suddenly, my entire page got stuck in the loading state. Thatโs when I realized โ if even one API is slow or fails, the whole UI becomes unusable.
And thatโs when I discovered Parallel Routes ๐.
How it works
- Create two folders with the
@
prefix inside the parent folder. These are called slots.
- Inside each, add a
page.tsx
like we normally would. - Create a
layout.tsx
file at the root level. - Inside the layout, receive both
route1
androute2
as props, along withchildren
.
Now, both routes can have their own loading.tsx
and error.tsx
.
๐ If one route is slow or crashes, the other still loads perfectly fine.
Your page wonโt be stuck anymore just because one API decides to take a nap.
Code Snippet
So next time an API ghosted you, donโt let it freeze your UI. Use parallel routes and keep things running smooth.
๐ก Thank me later.