Juxt
免費訂閱
文章 · 收錄於 2024.08
MGN-BLOG-NEXTJS-M
索引 · 部落格

NextJS Modal with shadcn for Intercepting and Parallel Routes

2 分鐘閱讀

What is Intercepting Route and Parallel Routes?

Intercepting Routes was a new feature firstly released in NextJS 13. Currently NextJS file-based route system is like a sitemap, there are no specific order on how the route is read or triggered. In NextJS documentation, it also wrote:

Note that the (..) convention is based on route segments, not the file-system.

Intercepting route thinks differently by thinking how would a user enters a route. Common browsing patterns like news feed, photo gallery or shopping cart, an array of items that user want to browse or collect. Users want to browse briefly bu

Parallel routes is another concept within NextJS

Why Intercepting & Parallel Routes

As explained in NextJS documentation, modal often are temporary actions or preview. We do not want alter user flow by redirecting back and forth. It's a very common behavior pattern when user is in a exploration mindset. E.g. surfing an instagram feed or browsing a photo gallery. Modal is a way to address this pattern by:

Making the modal content shareable through a URL. Preserving context when the page is refreshed, instead of closing the modal. Closing the modal on backwards navigation rather than going to the previous route. Reopening the modal on forwards navigation.

Setting it up

Let's try using shadcn/ui which offer modal component already.

Start by using

標籤Nextjs
索引 · 相關文章

延伸閱讀

文章 · 01
預覽圖
nextjs
Migrating from Gatsby to Next.js 14

This website has entered v3 of its iteration! v2 was created using Gatsby and integrated with my previous design resources `dojo.today`. Entering v3, I'm migrating the website from Gatsby to Next.js 14! Things that I'm considering during the revamp: For me there are two key pillar of content that require to migrate from this website 1. Blog articles on juxtdesign.cc that previously saved as Markd

部落格
文章 · 02
預覽圖
nextjs
PrevNext Blog Component for NextJS Using ContentLayer

Using ContentLayer, it's easy to create a Prev & Next component if you want to encourage users to read one blog article and then the order. All it takes are two simple step. 1. Create related posts logic on blog single page You should already have blog single page setup in the file like `/blog/[slug].tsx`. In addition to it you will need to create an index of posts, assuming you want to build a ch

部落格