-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmiddleware.ts
More file actions
26 lines (22 loc) · 929 Bytes
/
middleware.ts
File metadata and controls
26 lines (22 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { type NextRequest, NextResponse } from 'next/server'
// Takes care of redirecting /studio to /studio/en as Sanity Studio workspaces requires the same number of
// path segments in `basePath`. In other words, two workspaces with basePath `/en/studio` and '/no/studio' is allowed
// while `/studio` and '/no/studio' is not
export const config = {
matcher: '/studio/:tool*',
}
export function middleware(request: NextRequest) {
// @TODO come back to this later and figure out how to make it work without causing an infinite redirect loop
/*
const { pathname } = new URL(request.url)
if (
pathname.endsWith(request.nextUrl.pathname) &&
!pathname.endsWith(`${request.nextUrl.locale}${request.nextUrl.pathname}`)
) {
const url = request.nextUrl.clone()
url.pathname = `/${request.nextUrl.locale}${request.nextUrl.pathname}`
return NextResponse.redirect(url)
}
// */
return undefined
}