Home > Back-end >  How Can I do the dynamic redirects in nextjs
How Can I do the dynamic redirects in nextjs

Time:05-19

I currently have a Next.js application which have dynamic routing. I have URLs of this form /o/:organizationIdentifier*/p/:projectIdentifier*/e/:environmentIdentifier*/settings/notification/categories

I want to create a documentation which won't need to specify the organizationIdentifier, projectIdentifier or environmentIdentifier. A user will just click on a link like, /settings/notification/categories and it will redirect them to the /o/:organizationIdentifier*/p/:projectIdentifier*/e/:environmentIdentifier*/settings/notification/categories and these variables will be pulled from a redux store. However, I tried something like:

const rewrites = [
  {
    source: "/settings/notification/categories",
    destination: "/o/:organizationIdentifier*/p/:projectIdentifier*/e/:environmentIdentifier*/settings/notification/categories",
    "permanent":true,
    "locale":false
  }
]

but I keep getting errors:

destination has segments not in source or has (organizationIdentifier, projectIdentifier, environmentIdentifier) for route {"source":"/settings/notification/categories","destination":"/o/:organizationIdentifier*/p/:projectIdentifier*/e/:environmentIdentifier*/settings/notification/categories","permanent":true,"locale":false}`

and

Error: Invalid redirects found

Any help on how I can achieve this functionality?

CodePudding user response:

  {
    source: '/about',
    destination: '/',
    permanent: true,
  },

CodePudding user response:

    <Link
      href={{
        pathname: '/about',
        query: { name: 'test' },
      }}
    >
      <a>About us</a>
    </Link>
  • Related