Skip to content

Commit

Permalink
Iteration 3
Browse files Browse the repository at this point in the history
  • Loading branch information
javivelasco committed Jun 15, 2022
1 parent 110774d commit dfb2ba3
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions packages/next/server/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { matchHas } from '../shared/lib/router/utils/prepare-destination'
import { removePathPrefix } from '../shared/lib/router/utils/remove-path-prefix'
import { getRequestMeta } from './request-meta'
import { addPathPrefix } from '../shared/lib/router/utils/add-path-prefix'
import { getNextPathnameInfo } from '../shared/lib/router/utils/get-next-pathname-info'

type RouteResult = {
finished: boolean
Expand Down Expand Up @@ -300,6 +301,21 @@ export default class Router {
// if it is set
let currentPathname = parsedUrlUpdated.pathname as string
const originalPathname = currentPathname
const pathnameInfo = getNextPathnameInfo(originalPathname, {
nextConfig: this.nextConfig,
parseData: false,
})

// don't match API routes when they are locale prefixed
// e.g. /api/hello shouldn't match /en/api/hello as a page
// rewrites/redirects can match though
if (
!customRouteTypes.has(testRoute.type) &&
pathnameInfo.locale &&
pathnameInfo.pathname.match(/^\/api(?:\/|$)/)
) {
continue
}

const currentPathnameNoBasePath = removePathPrefix(
currentPathname,
Expand All @@ -314,26 +330,10 @@ export default class Router {
currentPathname = currentPathnameNoBasePath
}

const localePathResult = normalizeLocalePath(
currentPathnameNoBasePath,
this.locales
)

// don't match API routes when they are locale prefixed
// e.g. /api/hello shouldn't match /en/api/hello as a page
// rewrites/redirects can match though
if (
!customRouteTypes.has(testRoute.type) &&
localePathResult.detectedLocale &&
localePathResult.pathname.match(/^\/api(?:\/|$)/)
) {
continue
}

if (
customRouteTypes.has(testRoute.type) &&
!testRoute.internal &&
!localePathResult.detectedLocale &&
!pathnameInfo.locale &&
parsedUrl.query.__nextLocale
) {
currentPathname = addPathPrefix(
Expand Down

0 comments on commit dfb2ba3

Please sign in to comment.