Next.js Discord

Discord Forum

How to separate the loading.jsx file in App Routes?

Unanswered
Icelandic Sheepdog posted this in #help-forum
Open in Discord
Icelandic SheepdogOP
Situation:
I have route like: blog/[blog_id]
and file structure like blog->(page.jsx,loading.jsx), blog/[blog_id] -> (page.jsx,loading.jsx)
Question:
when I go to blog/[blog_id] as a detail page, first comes the blog/loading, then blog/[blog_id]/loading
Actually, the blog/loading is not suitable for detail page.

How to avoid the blog/loading?

1 Reply

Icelandic SheepdogOP
Solution: Use Route Groups to isolate loading states
Create route groups to prevent loading state inheritance:

app/
├── blog/
│   └── (list)/
│       ├── page.jsx                // Blog list at /blog
│       └── loading.jsx             // Only for list
└── blog/
    └── [blog_id]/
        ├── page.jsx                // Blog detail
        └── loading.jsx             // Only for detail


Ask claude4.0 and it seems work