Unverified Commit daab64c2 authored by Javi Velasco's avatar Javi Velasco Committed by GitHub

Extract router utils to common functions (#37313)

* Extract `detect-domain-locale` to a util file

* Remove `pathNoQueryHash` in favor of `parsePath`

* Remove `hasPathPrefix` in favor of `pathHasPrefix`

* Remove `addPathPrefix` in favor of an existing util

* Bugfix parsing pathname

* Refactor `addLocale`

* Extract `removeLocale`

* Extract `basePath` utils

* Dynamic imports for `getDomainLocale`
parent e7f55004
import { addPathPrefix } from '../shared/lib/router/utils/add-path-prefix'
import { normalizePathTrailingSlash } from './normalize-trailing-slash'
const basePath = (process.env.__NEXT_ROUTER_BASEPATH as string) || ''
export function addBasePath(path: string, required?: boolean): string {
if (process.env.__NEXT_MANUAL_CLIENT_BASE_PATH) {
if (!required) {
return path
}
}
return normalizePathTrailingSlash(addPathPrefix(path, basePath))
}
import type { addLocale as Fn } from '../shared/lib/router/utils/add-locale'
import { normalizePathTrailingSlash } from './normalize-trailing-slash'
export const addLocale: typeof Fn = (path, ...args) => {
if (process.env.__NEXT_I18N_SUPPORT) {
return normalizePathTrailingSlash(
require('../shared/lib/router/utils/add-locale').addLocale(path, ...args)
)
}
return path
}
import type { detectDomainLocale as Fn } from '../shared/lib/i18n/detect-domain-locale'
export const detectDomainLocale: typeof Fn = (...args) => {
if (process.env.__NEXT_I18N_SUPPORT) {
return require('../shared/lib/i18n/detect-domain-locale').detectDomainLocale(
...args
)
}
}
import type { DomainLocale } from '../server/config'
import type { normalizeLocalePath as NormalizeFn } from './normalize-locale-path'
import type { detectDomainLocale as DetectFn } from './detect-domain-locale'
const basePath = (process.env.__NEXT_ROUTER_BASEPATH as string) || ''
export function getDomainLocale(
path: string,
locale?: string | false,
locales?: string[],
domainLocales?: DomainLocale[]
) {
if (process.env.__NEXT_I18N_SUPPORT) {
const normalizeLocalePath: typeof NormalizeFn =
require('./normalize-locale-path').normalizeLocalePath
const detectDomainLocale: typeof DetectFn =
require('./detect-domain-locale').detectDomainLocale
const target = locale || normalizeLocalePath(path, locales).detectedLocale
const domain = detectDomainLocale(domainLocales, undefined, target)
if (domain) {
const proto = `http${domain.http ? '' : 's'}://`
const finalLocale = target === domain.defaultLocale ? '' : `/${target}`
return `${proto}${domain.domain}${basePath}${finalLocale}${path}`
}
return false
} else {
return false
}
}
import { pathHasPrefix } from '../shared/lib/router/utils/path-has-prefix'
const basePath = (process.env.__NEXT_ROUTER_BASEPATH as string) || ''
export function hasBasePath(path: string): boolean {
return pathHasPrefix(path, basePath)
}
...@@ -8,8 +8,6 @@ import type Router from '../shared/lib/router/router' ...@@ -8,8 +8,6 @@ import type Router from '../shared/lib/router/router'
import { import {
AppComponent, AppComponent,
AppProps, AppProps,
delBasePath,
hasBasePath,
PrivateRouteInfo, PrivateRouteInfo,
} from '../shared/lib/router/router' } from '../shared/lib/router/router'
import { isDynamicRoute } from '../shared/lib/router/utils/is-dynamic' import { isDynamicRoute } from '../shared/lib/router/utils/is-dynamic'
...@@ -35,6 +33,8 @@ import { getProperError } from '../lib/is-error' ...@@ -35,6 +33,8 @@ import { getProperError } from '../lib/is-error'
import { RefreshContext } from './streaming/refresh' import { RefreshContext } from './streaming/refresh'
import { ImageConfigContext } from '../shared/lib/image-config-context' import { ImageConfigContext } from '../shared/lib/image-config-context'
import { ImageConfigComplete } from '../shared/lib/image-config' import { ImageConfigComplete } from '../shared/lib/image-config'
import { removeBasePath } from './remove-base-path'
import { hasBasePath } from './has-base-path'
const ReactDOM = process.env.__NEXT_REACT_ROOT const ReactDOM = process.env.__NEXT_REACT_ROOT
? require('react-dom/client') ? require('react-dom/client')
...@@ -206,7 +206,7 @@ export async function initialize(opts: { webpackHMR?: any } = {}): Promise<{ ...@@ -206,7 +206,7 @@ export async function initialize(opts: { webpackHMR?: any } = {}): Promise<{
// make sure not to attempt stripping basePath for 404s // make sure not to attempt stripping basePath for 404s
if (hasBasePath(asPath)) { if (hasBasePath(asPath)) {
asPath = delBasePath(asPath) asPath = removeBasePath(asPath)
} }
if (process.env.__NEXT_I18N_SUPPORT) { if (process.env.__NEXT_I18N_SUPPORT) {
......
import React from 'react' import React from 'react'
import { UrlObject } from 'url' import { UrlObject } from 'url'
import { import {
addBasePath,
addLocale,
getDomainLocale,
isLocalURL, isLocalURL,
NextRouter, NextRouter,
PrefetchOptions, PrefetchOptions,
resolveHref, resolveHref,
} from '../shared/lib/router/router' } from '../shared/lib/router/router'
import { addLocale } from './add-locale'
import { RouterContext } from '../shared/lib/router-context' import { RouterContext } from '../shared/lib/router-context'
import { AppRouterContext } from '../shared/lib/app-router-context' import { AppRouterContext } from '../shared/lib/app-router-context'
import { useIntersection } from './use-intersection' import { useIntersection } from './use-intersection'
import { getDomainLocale } from './get-domain-locale'
import { addBasePath } from './add-base-path'
type Url = string | UrlObject type Url = string | UrlObject
type RequiredKeys<T> = { type RequiredKeys<T> = {
...@@ -422,12 +422,7 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkPropsReal>( ...@@ -422,12 +422,7 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkPropsReal>(
const localeDomain = const localeDomain =
router && router &&
router.isLocaleDomain && router.isLocaleDomain &&
getDomainLocale( getDomainLocale(as, curLocale, router.locales, router.domainLocales)
as,
curLocale,
router && router.locales,
router && router.domainLocales
)
childProps.href = childProps.href =
localeDomain || localeDomain ||
......
import type { normalizeLocalePath as Fn } from '../shared/lib/i18n/normalize-locale-path'
export const normalizeLocalePath: typeof Fn = (pathname, locales) => {
if (process.env.__NEXT_I18N_SUPPORT) {
return require('../shared/lib/i18n/normalize-locale-path').normalizeLocalePath(
pathname,
locales
)
}
return { pathname, detectedLocale: undefined }
}
import { removeTrailingSlash } from '../shared/lib/router/utils/remove-trailing-slash' import { removeTrailingSlash } from '../shared/lib/router/utils/remove-trailing-slash'
import { parsePath } from '../shared/lib/router/utils/parse-path'
/** /**
* Normalizes the trailing slash of a path according to the `trailingSlash` option * Normalizes the trailing slash of a path according to the `trailingSlash` option
* in `next.config.js`. * in `next.config.js`.
*/ */
export const normalizePathTrailingSlash = process.env.__NEXT_TRAILING_SLASH export const normalizePathTrailingSlash = (path: string) => {
? (path: string): string => { if (!path.startsWith('/')) {
if (/\.[^/]+\/?$/.test(path)) { return path
return removeTrailingSlash(path) }
} else if (path.endsWith('/')) {
return path const { pathname, query, hash } = parsePath(path)
} else { if (process.env.__NEXT_TRAILING_SLASH) {
return path + '/' if (/\.[^/]+\/?$/.test(pathname)) {
} return `${removeTrailingSlash(pathname)}${query}${hash}`
} else if (pathname.endsWith('/')) {
return `${pathname}${query}${hash}`
} else {
return `${pathname}/${query}${hash}`
} }
: removeTrailingSlash }
return `${removeTrailingSlash(pathname)}${query}${hash}`
}
import type { ComponentType } from 'react' import type { ComponentType } from 'react'
import type { RouteLoader } from './route-loader' import type { RouteLoader } from './route-loader'
import { import { addBasePath } from './add-base-path'
addBasePath, import { interpolateAs } from '../shared/lib/router/router'
addLocale,
interpolateAs,
} from '../shared/lib/router/router'
import getAssetPathFromRoute from '../shared/lib/router/utils/get-asset-path-from-route' import getAssetPathFromRoute from '../shared/lib/router/utils/get-asset-path-from-route'
import { addLocale } from './add-locale'
import { isDynamicRoute } from '../shared/lib/router/utils/is-dynamic' import { isDynamicRoute } from '../shared/lib/router/utils/is-dynamic'
import { parseRelativeUrl } from '../shared/lib/router/utils/parse-relative-url' import { parseRelativeUrl } from '../shared/lib/router/utils/parse-relative-url'
import { removeTrailingSlash } from '../shared/lib/router/utils/remove-trailing-slash' import { removeTrailingSlash } from '../shared/lib/router/utils/remove-trailing-slash'
......
import { hasBasePath } from './has-base-path'
const basePath = (process.env.__NEXT_ROUTER_BASEPATH as string) || ''
export function removeBasePath(path: string): string {
if (process.env.__NEXT_MANUAL_CLIENT_BASE_PATH) {
if (!hasBasePath(path)) {
return path
}
}
path = path.slice(basePath.length)
if (!path.startsWith('/')) path = `/${path}`
return path
}
import { parsePath } from '../shared/lib/router/utils/parse-path'
export function removeLocale(path: string, locale?: string) {
if (process.env.__NEXT_I18N_SUPPORT) {
const { pathname } = parsePath(path)
const pathLower = pathname.toLowerCase()
const localeLower = locale?.toLowerCase()
return locale &&
(pathLower.startsWith(`/${localeLower}/`) ||
pathLower === `/${localeLower}`)
? `${pathname.length === locale.length + 1 ? `/` : ``}${path.slice(
locale.length + 1
)}`
: path
}
return path
}
...@@ -37,6 +37,13 @@ import resolveRewrites from './utils/resolve-rewrites' ...@@ -37,6 +37,13 @@ import resolveRewrites from './utils/resolve-rewrites'
import { getRouteMatcher } from './utils/route-matcher' import { getRouteMatcher } from './utils/route-matcher'
import { getRouteRegex, getMiddlewareRegex } from './utils/route-regex' import { getRouteRegex, getMiddlewareRegex } from './utils/route-regex'
import { formatWithValidation } from './utils/format-url' import { formatWithValidation } from './utils/format-url'
import { detectDomainLocale } from '../../../client/detect-domain-locale'
import { parsePath } from './utils/parse-path'
import { addLocale } from '../../../client/add-locale'
import { removeLocale } from '../../../client/remove-locale'
import { removeBasePath } from '../../../client/remove-base-path'
import { addBasePath } from '../../../client/add-base-path'
import { hasBasePath } from '../../../client/has-base-path'
declare global { declare global {
interface Window { interface Window {
...@@ -97,134 +104,12 @@ export type HistoryState = ...@@ -97,134 +104,12 @@ export type HistoryState =
| { __N: false } | { __N: false }
| ({ __N: true; key: string } & NextHistoryState) | ({ __N: true; key: string } & NextHistoryState)
let detectDomainLocale: typeof import('../i18n/detect-domain-locale').detectDomainLocale
if (process.env.__NEXT_I18N_SUPPORT) {
detectDomainLocale =
require('../i18n/detect-domain-locale').detectDomainLocale
}
const basePath = (process.env.__NEXT_ROUTER_BASEPATH as string) || ''
function buildCancellationError() { function buildCancellationError() {
return Object.assign(new Error('Route Cancelled'), { return Object.assign(new Error('Route Cancelled'), {
cancelled: true, cancelled: true,
}) })
} }
function addPathPrefix(path: string, prefix?: string) {
if (!path.startsWith('/') || !prefix) {
return path
}
const pathname = pathNoQueryHash(path)
return (
normalizePathTrailingSlash(`${prefix}${pathname}`) +
path.slice(pathname.length)
)
}
function hasPathPrefix(path: string, prefix: string) {
path = pathNoQueryHash(path)
return path === prefix || path.startsWith(prefix + '/')
}
export function getDomainLocale(
path: string,
locale?: string | false,
locales?: string[],
domainLocales?: DomainLocale[]
) {
if (process.env.__NEXT_I18N_SUPPORT) {
locale = locale || normalizeLocalePath(path, locales).detectedLocale
const detectedDomain = detectDomainLocale(domainLocales, undefined, locale)
if (detectedDomain) {
return `http${detectedDomain.http ? '' : 's'}://${detectedDomain.domain}${
basePath || ''
}${locale === detectedDomain.defaultLocale ? '' : `/${locale}`}${path}`
}
return false
} else {
return false
}
}
export function addLocale(
path: string,
locale?: string | false,
defaultLocale?: string
) {
if (process.env.__NEXT_I18N_SUPPORT) {
if (locale && locale !== defaultLocale) {
const pathname = pathNoQueryHash(path)
const pathLower = pathname.toLowerCase()
const localeLower = locale.toLowerCase()
if (
!hasPathPrefix(pathLower, '/' + localeLower) &&
!hasPathPrefix(pathLower, '/api')
) {
return addPathPrefix(path, '/' + locale)
}
}
}
return path
}
export function delLocale(path: string, locale?: string) {
if (process.env.__NEXT_I18N_SUPPORT) {
const pathname = pathNoQueryHash(path)
const pathLower = pathname.toLowerCase()
const localeLower = locale && locale.toLowerCase()
return locale &&
(pathLower.startsWith('/' + localeLower + '/') ||
pathLower === '/' + localeLower)
? (pathname.length === locale.length + 1 ? '/' : '') +
path.slice(locale.length + 1)
: path
}
return path
}
function pathNoQueryHash(path: string) {
const queryIndex = path.indexOf('?')
const hashIndex = path.indexOf('#')
if (queryIndex > -1 || hashIndex > -1) {
path = path.substring(0, queryIndex > -1 ? queryIndex : hashIndex)
}
return path
}
export function hasBasePath(path: string): boolean {
return hasPathPrefix(path, basePath)
}
export function addBasePath(path: string, required?: boolean): string {
if (process.env.__NEXT_MANUAL_CLIENT_BASE_PATH) {
if (!required) {
return path
}
}
// we only add the basepath on relative urls
return addPathPrefix(path, basePath)
}
export function delBasePath(path: string): string {
if (process.env.__NEXT_MANUAL_CLIENT_BASE_PATH) {
if (!hasBasePath(path)) {
return path
}
}
path = path.slice(basePath.length)
if (!path.startsWith('/')) path = `/${path}`
return path
}
/** /**
* Detects whether a given url is routable by the Next.js router (browser only). * Detects whether a given url is routable by the Next.js router (browser only).
*/ */
...@@ -754,7 +639,7 @@ export default class Router implements BaseRouter { ...@@ -754,7 +639,7 @@ export default class Router implements BaseRouter {
const autoExportDynamic = const autoExportDynamic =
isDynamicRoute(pathname) && self.__NEXT_DATA__.autoExport isDynamicRoute(pathname) && self.__NEXT_DATA__.autoExport
this.basePath = basePath this.basePath = (process.env.__NEXT_ROUTER_BASEPATH as string) || ''
this.sub = subscription this.sub = subscription
this.clc = null this.clc = null
this._wrapApp = wrapApp this._wrapApp = wrapApp
...@@ -973,7 +858,7 @@ export default class Router implements BaseRouter { ...@@ -973,7 +858,7 @@ export default class Router implements BaseRouter {
const shouldResolveHref = const shouldResolveHref =
(options as any)._h || (options as any)._h ||
(options as any)._shouldResolveHref || (options as any)._shouldResolveHref ||
pathNoQueryHash(url) === pathNoQueryHash(as) parsePath(url).pathname === parsePath(as).pathname
const nextState = { const nextState = {
...this.state, ...this.state,
...@@ -997,7 +882,9 @@ export default class Router implements BaseRouter { ...@@ -997,7 +882,9 @@ export default class Router implements BaseRouter {
options.locale = nextState.locale options.locale = nextState.locale
} }
const parsedAs = parseRelativeUrl(hasBasePath(as) ? delBasePath(as) : as) const parsedAs = parseRelativeUrl(
hasBasePath(as) ? removeBasePath(as) : as
)
const localePathResult = normalizeLocalePath( const localePathResult = normalizeLocalePath(
parsedAs.pathname, parsedAs.pathname,
this.locales this.locales
...@@ -1009,7 +896,7 @@ export default class Router implements BaseRouter { ...@@ -1009,7 +896,7 @@ export default class Router implements BaseRouter {
as = formatWithValidation(parsedAs) as = formatWithValidation(parsedAs)
url = addBasePath( url = addBasePath(
normalizeLocalePath( normalizeLocalePath(
hasBasePath(url) ? delBasePath(url) : url, hasBasePath(url) ? removeBasePath(url) : url,
this.locales this.locales
).pathname ).pathname
) )
...@@ -1046,7 +933,7 @@ export default class Router implements BaseRouter { ...@@ -1046,7 +933,7 @@ export default class Router implements BaseRouter {
this.isLocaleDomain && this.isLocaleDomain &&
self.location.hostname !== detectedDomain.domain self.location.hostname !== detectedDomain.domain
) { ) {
const asNoBasePath = delBasePath(as) const asNoBasePath = removeBasePath(as)
window.location.href = `http${detectedDomain.http ? '' : 's'}://${ window.location.href = `http${detectedDomain.http ? '' : 's'}://${
detectedDomain.domain detectedDomain.domain
}${addBasePath( }${addBasePath(
...@@ -1084,13 +971,13 @@ export default class Router implements BaseRouter { ...@@ -1084,13 +971,13 @@ export default class Router implements BaseRouter {
as = addBasePath( as = addBasePath(
addLocale( addLocale(
hasBasePath(as) ? delBasePath(as) : as, hasBasePath(as) ? removeBasePath(as) : as,
options.locale, options.locale,
this.defaultLocale this.defaultLocale
) )
) )
const cleanedAs = delLocale( const cleanedAs = removeLocale(
hasBasePath(as) ? delBasePath(as) : as, hasBasePath(as) ? removeBasePath(as) : as,
nextState.locale nextState.locale
) )
this._inFlightRoute = as this._inFlightRoute = as
...@@ -1167,7 +1054,9 @@ export default class Router implements BaseRouter { ...@@ -1167,7 +1054,9 @@ export default class Router implements BaseRouter {
// url and as should always be prefixed with basePath by this // url and as should always be prefixed with basePath by this
// point by either next/link or router.push/replace so strip the // point by either next/link or router.push/replace so strip the
// basePath from the pathname to match the pages dir 1-to-1 // basePath from the pathname to match the pages dir 1-to-1
pathname = pathname ? removeTrailingSlash(delBasePath(pathname)) : pathname pathname = pathname
? removeTrailingSlash(removeBasePath(pathname))
: pathname
if (shouldResolveHref && pathname !== '/_error') { if (shouldResolveHref && pathname !== '/_error') {
;(options as any)._shouldResolveHref = true ;(options as any)._shouldResolveHref = true
...@@ -1218,7 +1107,7 @@ export default class Router implements BaseRouter { ...@@ -1218,7 +1107,7 @@ export default class Router implements BaseRouter {
return false return false
} }
resolvedAs = delLocale(delBasePath(resolvedAs), nextState.locale) resolvedAs = removeLocale(removeBasePath(resolvedAs), nextState.locale)
/** /**
* If the route update was triggered for client-side hydration and * If the route update was triggered for client-side hydration and
...@@ -1824,7 +1713,10 @@ export default class Router implements BaseRouter { ...@@ -1824,7 +1713,10 @@ export default class Router implements BaseRouter {
if (rewritesResult.externalDest) { if (rewritesResult.externalDest) {
return return
} }
resolvedAs = delLocale(delBasePath(rewritesResult.asPath), this.locale) resolvedAs = removeLocale(
removeBasePath(rewritesResult.asPath),
this.locale
)
if (rewritesResult.matchedPage && rewritesResult.resolvedHref) { if (rewritesResult.matchedPage && rewritesResult.resolvedHref) {
// if this directly matches a page we need to update the href to // if this directly matches a page we need to update the href to
...@@ -1965,9 +1857,9 @@ export default class Router implements BaseRouter { ...@@ -1965,9 +1857,9 @@ export default class Router implements BaseRouter {
locale: string | undefined locale: string | undefined
isPreview: boolean isPreview: boolean
}): Promise<PreflightEffect> { }): Promise<PreflightEffect> {
const asPathname = pathNoQueryHash(options.as) const { pathname: asPathname } = parsePath(options.as)
const cleanedAs = delLocale( const cleanedAs = removeLocale(
hasBasePath(asPathname) ? delBasePath(asPathname) : asPathname, hasBasePath(asPathname) ? removeBasePath(asPathname) : asPathname,
options.locale options.locale
) )
...@@ -2013,7 +1905,7 @@ export default class Router implements BaseRouter { ...@@ -2013,7 +1905,7 @@ export default class Router implements BaseRouter {
const parsed = parseRelativeUrl( const parsed = parseRelativeUrl(
normalizeLocalePath( normalizeLocalePath(
hasBasePath(preflight.rewrite) hasBasePath(preflight.rewrite)
? delBasePath(preflight.rewrite) ? removeBasePath(preflight.rewrite)
: preflight.rewrite, : preflight.rewrite,
this.locales this.locales
).pathname ).pathname
...@@ -2052,7 +1944,7 @@ export default class Router implements BaseRouter { ...@@ -2052,7 +1944,7 @@ export default class Router implements BaseRouter {
const cleanRedirect = removeTrailingSlash( const cleanRedirect = removeTrailingSlash(
normalizeLocalePath( normalizeLocalePath(
hasBasePath(preflight.redirect) hasBasePath(preflight.redirect)
? delBasePath(preflight.redirect) ? removeBasePath(preflight.redirect)
: preflight.redirect, : preflight.redirect,
this.locales this.locales
).pathname ).pathname
......
...@@ -10,7 +10,10 @@ export function parsePath(path: string) { ...@@ -10,7 +10,10 @@ export function parsePath(path: string) {
if (queryIndex > -1 || hashIndex > -1) { if (queryIndex > -1 || hashIndex > -1) {
return { return {
pathname: path.substring(0, queryIndex > -1 ? queryIndex : hashIndex), pathname: path.substring(0, queryIndex > -1 ? queryIndex : hashIndex),
query: queryIndex > -1 ? path.substring(queryIndex, hashIndex) : '', query:
queryIndex > -1
? path.substring(queryIndex, hashIndex > -1 ? hashIndex : undefined)
: '',
hash: hashIndex > -1 ? path.slice(hashIndex) : '', hash: hashIndex > -1 ? path.slice(hashIndex) : '',
} }
} }
......
import { ParsedUrlQuery } from 'querystring' import type { ParsedUrlQuery } from 'querystring'
import { getPathMatch } from './path-match' import { getPathMatch } from './path-match'
import { matchHas, prepareDestination } from './prepare-destination' import { matchHas, prepareDestination } from './prepare-destination'
import { Rewrite } from '../../../../lib/load-custom-routes' import { Rewrite } from '../../../../lib/load-custom-routes'
import { removeTrailingSlash } from './remove-trailing-slash' import { removeTrailingSlash } from './remove-trailing-slash'
import { normalizeLocalePath } from '../../i18n/normalize-locale-path' import { normalizeLocalePath } from '../../i18n/normalize-locale-path'
import { removeBasePath } from '../../../../client/remove-base-path'
import { parseRelativeUrl } from './parse-relative-url' import { parseRelativeUrl } from './parse-relative-url'
import { delBasePath } from '../router'
export default function resolveRewrites( export default function resolveRewrites(
asPath: string, asPath: string,
...@@ -29,7 +29,7 @@ export default function resolveRewrites( ...@@ -29,7 +29,7 @@ export default function resolveRewrites(
let externalDest = false let externalDest = false
let parsedAs = parseRelativeUrl(asPath) let parsedAs = parseRelativeUrl(asPath)
let fsPathname = removeTrailingSlash( let fsPathname = removeTrailingSlash(
normalizeLocalePath(delBasePath(parsedAs.pathname), locales).pathname normalizeLocalePath(removeBasePath(parsedAs.pathname), locales).pathname
) )
let resolvedHref let resolvedHref
...@@ -83,7 +83,7 @@ export default function resolveRewrites( ...@@ -83,7 +83,7 @@ export default function resolveRewrites(
Object.assign(query, destRes.parsedDestination.query) Object.assign(query, destRes.parsedDestination.query)
fsPathname = removeTrailingSlash( fsPathname = removeTrailingSlash(
normalizeLocalePath(delBasePath(asPath), locales).pathname normalizeLocalePath(removeBasePath(asPath), locales).pathname
) )
if (pages.includes(fsPathname)) { if (pages.includes(fsPathname)) {
......
/* eslint-env jest */ /* eslint-env jest */
import { addBasePath } from 'next/dist/shared/lib/router/router' import { addBasePath } from 'next/dist/client/add-base-path'
describe('router addBasePath', () => { describe('router addBasePath', () => {
it('should add basePath correctly when no basePath', () => { it('should add basePath correctly when no basePath', () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment