Skip to content

Commit

Permalink
Merge branch 'canary' into update/getserversideprops-invalid-return-v…
Browse files Browse the repository at this point in the history
…alue-format
  • Loading branch information
ijjk committed Apr 6, 2022
2 parents b953271 + 07723be commit 29058e0
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions docs/advanced-features/i18n-routing.md
Expand Up @@ -170,24 +170,19 @@ import { NextRequest, NextResponse } from 'next/server'

const PUBLIC_FILE = /\.(.*)$/

const stripDefaultLocale = (str: string): string => {
const stripped = str.replace('/default', '')
return stripped
}

export function middleware(request: NextRequest) {
const shouldHandleLocale =
!PUBLIC_FILE.test(request.nextUrl.pathname) &&
!request.nextUrl.pathname.includes('/api/') &&
request.nextUrl.locale === 'default'

return shouldHandleLocale
? NextResponse.redirect(
`/en${stripDefaultLocale(request.nextUrl.pathname)}${
request.nextUrl.search
}`
)
: undefined
if (shouldHandleLocale) {
const url = request.nextUrl.clone()
url.pathname = `/en${request.nextUrl.pathname}`
return NextResponse.redirect(url)
}

return undefined
}
```

Expand Down

0 comments on commit 29058e0

Please sign in to comment.