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

feat: Add support for basePath in middleware and navigation APIs #699

Merged
merged 8 commits into from
Dec 6, 2023

Conversation

amannn
Copy link
Owner

@amannn amannn commented Dec 6, 2023

There's no need for a new config option, next-intl will automatically pick up the basePath you've configured in next.config.js. Note however that you should make sure that you match / explicitly in your middleware matcher (see the updated docs).

The only integration points are:

  • Apply the basePath for redirects, as Next.js doesn't handle this internally
  • Apply the basePath for rewrites, as Next.js doesn't handle this internally
  • Apply the basePath for alternate links

This PR is based on the initial work in #589 by @Robjam

Closes #589
Closes #243

Robjam and others added 4 commits October 31, 2023 10:54
…annn

# Conflicts:
#	packages/next-intl/src/middleware/NextIntlMiddlewareConfig.tsx
#	packages/next-intl/src/middleware/getAlternateLinksHeaderValue.tsx
#	packages/next-intl/src/middleware/middleware.tsx
#	packages/next-intl/src/middleware/resolveLocale.tsx
#	packages/next-intl/test/middleware/middleware.test.tsx
Copy link

vercel bot commented Dec 6, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-intl-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 6, 2023 1:24pm
next-intl-example-app-router ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 6, 2023 1:24pm

@@ -187,19 +194,19 @@ export default function createMiddleware<Locales extends AllLocales>(
);

if (hasLocalePrefix) {
const basePath = getNormalizedPathname(
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed getNormalizedPathname here because it's not necessary (already applied above)

@amannn amannn changed the title feat: Support for basePath feat: Support for basePath in middleware and navigation APIs Dec 6, 2023
@amannn amannn changed the title feat: Support for basePath in middleware and navigation APIs feat: Add support for basePath in middleware and navigation APIs Dec 6, 2023
@amannn amannn marked this pull request as ready for review December 6, 2023 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Middleware: Support for basePath in the app directory
2 participants