Next.js Discord

Discord Forum

Route Interception is not working as intended

Unanswered
HOTCONQUEROR posted this in #help-forum
Open in Discord
Here is the routes structure in the image,

and here is my code for the base route:

 const mapBlog = () =>{
    return blog?.map((bl,idx)=>{
      return(
        <div key={idx} className='flex flex-col flex-wrap w-[600px] h-[600px] gap-5 border p-8 rounded-md'>
        
          <Link href={{pathname: `/blog/${bl.id}/`
        }}>
          
            <div className='' id='img'><Image height={500} width={500} className='' alt='title_img' key={idx} src={bl.image}></Image></div>
         
          <div className='flex justify-center text-2xl font-bold' id='title'>{bl.title}</div>
          </Link>
          <div className='flex flex-row flex-nowrap justify-between w-[500px]'>
          <div className='' id='username'>{bl._username} </div>
          <div className='' id='created_at'> {new Date(bl.created_at).toLocaleDateString('en-gb',{
            day:'numeric',
            month:'long',
            year:'numeric'
          })}</div>
          </div>
          <div className ='' id='tags'>{bl.tags.map((tag)=>{
            return(
            <div key='' className='flex flex-row flex-nowrap gap-1'>
              <button className="">#{tag}</button>
            </div>
            )
          })}</div>

        </div>
      )
    })
  }


and here is my code for the blog/[id] route:

   return(
        <Modal isOpen={true}>
            <ModalHeader>{blog?.title}</ModalHeader>
        </Modal>
    )
i am using next-ui Modal, I still get redirected to a different page, but this is not supposed to happen with route interception, i can't figure out how to fix this?

2nd problem: when I reload the page where the Modal is, it gives me 404 not found?

20 Replies

Brown bear
I think you're talking about Parallel Routes, not intercepting routes:
https://nextjs.org/docs/app/building-your-application/routing/intercepting-routes#examples
@Brown bear I think you're talking about Parallel Routes, not intercepting routes: https://nextjs.org/docs/app/building-your-application/routing/intercepting-routes#examples
but i need intercepting routes so that i can navigate to a different route without actually loading it
@Brown bear And https://nextjs.org/docs/app/building-your-application/routing/parallel-routes#modals
regardless, isn't that what i am doing in my project?
like, i got the (...) to match base route.
@HOTCONQUEROR like, i got the `(...)` to match base route.
Brown bear
The only thing I see that is different is you don't have your modal in a slot @modal like they have
@Brown bear The only thing I see that is different is you don't have your modal in a slot `@modal ` like they have
i still don't understand, why do i need parallel route here?
i assume @ operator in folders is for parallel route
Brown bear
What are you trying to do?
@Brown bear What are you trying to do?
open another page/route from the current route, without actually navigating to that route, basically, the first route is main page, the 2nd one is a modal, i wanted to open the modal from some button in the main page, where i don't need to navigate to the 2nd page (which actually contain the modal), make sense?
parallel routes are for having 2 routes rendered in the same view afaik.
Brown bear
Thinking you might want to take a look at https://github.com/vercel/nextgram/tree/main
@HOTCONQUEROR parallel routes are for having 2 routes rendered in the same view afaik.
Brown bear
You do have 2 routes rendered in the same view though, 1 is your main page, 1 is your blog modal
I think you also need to have a normal blog route, so that it has something to intercept
@Brown bear You do have 2 routes rendered in the same view though, 1 is your main page, 1 is your blog modal
ok, for the 2nd problem, the dynamic route when reloaded is giving me 404 not found
@HOTCONQUEROR ok, for the 2nd problem, the dynamic route when reloaded is giving me 404 not found
Brown bear
I think it is because you don't have a blog/[id]/page.tsx file
Brown bear
You have the interception path, but not the real one. So when reloading, there is no where to go.
@Brown bear You have the interception path, but not the real one. So when reloading, there is no where to go.
i am experimenting on parallel routes, and now i am getting 404 on the main page