Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrites doesn't work with routes of custom page extension #22791

Closed
huozhi opened this issue Mar 5, 2021 · 3 comments
Closed

Rewrites doesn't work with routes of custom page extension #22791

huozhi opened this issue Mar 5, 2021 · 3 comments
Labels
bug Issue was opened via the bug report template.

Comments

@huozhi
Copy link
Member

huozhi commented Mar 5, 2021

What version of Next.js are you using?

10.0.7

What version of Node.js are you using?

12.20.1

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

next dev, codesandbox

Describe the Bug

When rewrite path matches custom page extension, visiting path with page extension results in 404.

Example

// next.config.js
module.exports = {
  pageExtensions: ["page.js", "js"],
  async rewrites() {
    return [
      {
        source: "/:slug*.page",
        destination: "/:slug*"
      }
    ];
  }
};
- pages/
  |- about.page.js

This issue only occurs in development mode. Production mode (next build) works well

Observed behavior

  • Visit /about result the content of about.page.js
  • Visit /about.page result 404

Expected Behavior

  • Visit /about should result the content of about.page.js
  • Visit /about.page should result the content of about.page.js as well

To Reproduce

https://codesandbox.io/s/nextjs-page-ext-k5xp6

@huozhi huozhi added the bug Issue was opened via the bug report template. label Mar 5, 2021
@huozhi huozhi closed this as completed Mar 12, 2021
@huozhi huozhi reopened this Mar 13, 2021
@huozhi
Copy link
Member Author

huozhi commented Mar 13, 2021

After digging, I found in the rewrite are been executed in this case while running next dev.

// router.ts
const allRoutes = [
      ...this.headers,
      ...this.redirects,
      ...this.fsRoutes,
      page checker,
      ...this.rewrites
]

Each time I visit /about.page which should be rewritten to /about, it will go through router.execute for all routes, but end at the page checker. The rewrites I've configured at next.config.js will be skipped.

@huozhi
Copy link
Member Author

huozhi commented Apr 26, 2021

This issue is resolved by #23407 with usage of rewrites.beforeFiles

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

2 participants