Next.js Discord

Discord Forum

Can't get Intercepting Routes to work with rewrites

Unanswered
Kanni posted this in #help-forum
Open in Discord
Avatar
KanniOP
I've managed to get intercepting routes working with parallel routing to create modals like in https://nextjs.org/docs/app/building-your-application/routing/intercepting-routes#examples .

I'm using this so that any pages in /item/my-item-id appear as a popup/modal.

However I am also using a rewrite to change /@steve to /user/steve. Without this rewrite the interception works fine, however as soon as I enable it it stops working for all pages (so links to /item from /about stop working as a modal).

Although if I rewrite from /@/steve to /user/steve it works completely fine. I think this may be a bug in next with changing from 2 "path levels" to 1, but I just wanted to check I wasn't configuring something incorrectly.

  rewrites: async () => {
    return [
      {
        source: "/@:username",
        destination: "/user/:username",
      },
    ];
  },

This is my rewrites in next config. I've also tried it as a beforeFiles, afterFiles and Fallback, but none of them seem to work.

1 Reply

Avatar
KanniOP
this is my folder structure
Image