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

Middleware matcher does not match / for TrailingSlash: true + i18n #39396

Closed
1 task done
Grsmto opened this issue Aug 8, 2022 · 1 comment · Fixed by #39397
Closed
1 task done

Middleware matcher does not match / for TrailingSlash: true + i18n #39396

Grsmto opened this issue Aug 8, 2022 · 1 comment · Fixed by #39397
Labels
bug Issue was opened via the bug report template.

Comments

@Grsmto
Copy link

Grsmto commented Aug 8, 2022

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
Platform: linux
Arch: x64
Version: #45~20.04.1-Ubuntu SMP Mon Apr 4 09:38:31 UTC 2022
Binaries:
Node: 14.19.3
npm: 6.14.17
Yarn: 1.22.19
pnpm: N/A
Relevant packages:
next: 12.2.4
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

It seems like the middleware matcher does not match the homepage route / if trailingSlash is set to true along with some i18n config.

next.config.js

trailingSlash: true,
i18n: {
  locales: ["us", "uk", "eu"],
  defaultLocale: "us",
  localeDetection: false
}

along with the following middleware matcher

export const config = {
  matcher: "/"
};

Expected Behavior

When matcher is set to "/" the middleware should kick in on the homepage.

Link to reproduction

https://codesandbox.io/s/serene-morning-fd1cr1?file=/middleware.ts

To Reproduce

  • Load the reproduction example
  • Make sure you are on the homepage /
  • Refresh app
  • Look at the terminal logs, nothing is logged even though middleware.ts has a console.log in there
@Grsmto Grsmto added the bug Issue was opened via the bug report template. label Aug 8, 2022
feugy added a commit to feugy/next.js that referenced this issue Aug 8, 2022
ijjk added a commit that referenced this issue Aug 9, 2022
* feat(middleware): augments / matcher with /index

* fix(#39396): not invoked with i18n and trailingSlash

* add test case

* tweak matcher a bit and add tests

Co-authored-by: JJ Kasper <jj@jjsweb.site>
@github-actions
Copy link
Contributor

github-actions bot commented Sep 9, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 9, 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

Successfully merging a pull request may close this issue.

1 participant