0

I am trying to set up the routing with my next.js configuration. Whatever I tried so far did not produce the intended results. This is becoming confusing and frustrating for me, any help will be appreciated.

Here is what I want:

  • url goes to / => /index.js
  • url goes to /users/ => /user/index.js
  • url goes to /users/[user-id] => /user/user.js

Here is what doesn't work:

module.exports = {
  target: "serverless",
  async rewrites() {
    return {
        afterFiles: [
          {
            source: "/users/",
            destination: "/users/"
          },
          {
            source: "/users/:path*",
            destination: "/users/:path*"
          },
          {
            source: "/:path*",
            destination: "/:path*"
          },
          {
            source: "/:else*",
            destination: "/"
          }
      ]
    };
  },
};
fatih
  • 1,010
  • 1
  • 8
  • 20
  • I also tried renaming `user.js` to `[userId].js` which felt a bit weird but it didn't work either. – fatih Jan 06 '22 at 01:18
  • It's not clear what the issue is, and why you're using the config to setup the routing. What does your `pages` folder look like? Next.js has a file-system based router, when a file is added to the `pages directory`, it's automatically available as a route. See https://nextjs.org/docs/routing/introduction for details. – juliomalves Jan 08 '22 at 16:16

0 Answers0