Add namedRegex and routeKeys to routes manifest (#12250)
This commit is contained in:
parent
af33ebc35d
commit
52686690a9
7 changed files with 154 additions and 24 deletions
|
@ -299,10 +299,15 @@ export default async function build(dir: string, conf = null): Promise<void> {
|
||||||
redirects: redirects.map(r => buildCustomRoute(r, 'redirect')),
|
redirects: redirects.map(r => buildCustomRoute(r, 'redirect')),
|
||||||
rewrites: rewrites.map(r => buildCustomRoute(r, 'rewrite')),
|
rewrites: rewrites.map(r => buildCustomRoute(r, 'rewrite')),
|
||||||
headers: headers.map(r => buildCustomRoute(r, 'header')),
|
headers: headers.map(r => buildCustomRoute(r, 'header')),
|
||||||
dynamicRoutes: getSortedRoutes(dynamicRoutes).map(page => ({
|
dynamicRoutes: getSortedRoutes(dynamicRoutes).map(page => {
|
||||||
page,
|
const routeRegex = getRouteRegex(page)
|
||||||
regex: getRouteRegex(page).re.source,
|
return {
|
||||||
})),
|
page,
|
||||||
|
regex: routeRegex.re.source,
|
||||||
|
namedRegex: routeRegex.namedRegex,
|
||||||
|
routeKeys: Object.keys(routeRegex.groups),
|
||||||
|
}
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
await mkdir(distDir, { recursive: true })
|
await mkdir(distDir, { recursive: true })
|
||||||
|
@ -633,20 +638,37 @@ export default async function build(dir: string, conf = null): Promise<void> {
|
||||||
`${pagePath}.json`
|
`${pagePath}.json`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
let dataRouteRegex: string
|
||||||
|
let routeKeys: string[] | undefined
|
||||||
|
let namedDataRouteRegex: string | undefined
|
||||||
|
|
||||||
|
if (isDynamicRoute(page)) {
|
||||||
|
const routeRegex = getRouteRegex(dataRoute.replace(/\.json$/, ''))
|
||||||
|
|
||||||
|
dataRouteRegex = routeRegex.re.source.replace(
|
||||||
|
/\(\?:\\\/\)\?\$$/,
|
||||||
|
'\\.json$'
|
||||||
|
)
|
||||||
|
namedDataRouteRegex = routeRegex.namedRegex!.replace(
|
||||||
|
/\(\?:\/\)\?\$$/,
|
||||||
|
'\\.json$'
|
||||||
|
)
|
||||||
|
routeKeys = Object.keys(routeRegex.groups)
|
||||||
|
} else {
|
||||||
|
dataRouteRegex = new RegExp(
|
||||||
|
`^${path.posix.join(
|
||||||
|
'/_next/data',
|
||||||
|
escapeStringRegexp(buildId),
|
||||||
|
`${pagePath}.json`
|
||||||
|
)}$`
|
||||||
|
).source
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
page,
|
page,
|
||||||
dataRouteRegex: isDynamicRoute(page)
|
routeKeys,
|
||||||
? getRouteRegex(dataRoute.replace(/\.json$/, '')).re.source.replace(
|
dataRouteRegex,
|
||||||
/\(\?:\\\/\)\?\$$/,
|
namedDataRouteRegex,
|
||||||
'\\.json$'
|
|
||||||
)
|
|
||||||
: new RegExp(
|
|
||||||
`^${path.posix.join(
|
|
||||||
'/_next/data',
|
|
||||||
escapeStringRegexp(buildId),
|
|
||||||
`${pagePath}.json`
|
|
||||||
)}$`
|
|
||||||
).source,
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
|
// this isn't importing the escape-string-regex module
|
||||||
|
// to reduce bytes
|
||||||
|
function escapeRegex(str: string) {
|
||||||
|
return str.replace(/[|\\{}()[\]^$+*?.-]/g, '\\$&')
|
||||||
|
}
|
||||||
|
|
||||||
export function getRouteRegex(
|
export function getRouteRegex(
|
||||||
normalizedRoute: string
|
normalizedRoute: string
|
||||||
): {
|
): {
|
||||||
re: RegExp
|
re: RegExp
|
||||||
|
namedRegex?: string
|
||||||
groups: { [groupName: string]: { pos: number; repeat: boolean } }
|
groups: { [groupName: string]: { pos: number; repeat: boolean } }
|
||||||
} {
|
} {
|
||||||
// Escape all characters that could be considered RegEx
|
// Escape all characters that could be considered RegEx
|
||||||
const escapedRoute = (normalizedRoute.replace(/\/$/, '') || '/').replace(
|
const escapedRoute = escapeRegex(normalizedRoute.replace(/\/$/, '') || '/')
|
||||||
/[|\\{}()[\]^$+*?.-]/g,
|
|
||||||
'\\$&'
|
|
||||||
)
|
|
||||||
|
|
||||||
const groups: { [groupName: string]: { pos: number; repeat: boolean } } = {}
|
const groups: { [groupName: string]: { pos: number; repeat: boolean } } = {}
|
||||||
let groupIndex = 1
|
let groupIndex = 1
|
||||||
|
@ -28,8 +32,34 @@ export function getRouteRegex(
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
let namedParameterizedRoute: string | undefined
|
||||||
|
|
||||||
|
// dead code eliminate for browser since it's only needed
|
||||||
|
// while generating routes-manifest
|
||||||
|
if (typeof window === 'undefined') {
|
||||||
|
namedParameterizedRoute = escapedRoute.replace(
|
||||||
|
/\/\\\[([^/]+?)\\\](?=\/|$)/g,
|
||||||
|
(_, $1) => {
|
||||||
|
const isCatchAll = /^(\\\.){3}/.test($1)
|
||||||
|
const key = $1
|
||||||
|
// Un-escape key
|
||||||
|
.replace(/\\([|\\{}()[\]^$+*?.-])/g, '$1')
|
||||||
|
.replace(/^\.{3}/, '')
|
||||||
|
|
||||||
|
return isCatchAll
|
||||||
|
? `/(?<${escapeRegex(key)}>.+?)`
|
||||||
|
: `/(?<${escapeRegex(key)}>[^/]+?)`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
re: new RegExp('^' + parameterizedRoute + '(?:/)?$', 'i'),
|
re: new RegExp('^' + parameterizedRoute + '(?:/)?$', 'i'),
|
||||||
groups,
|
groups,
|
||||||
|
...(namedParameterizedRoute
|
||||||
|
? {
|
||||||
|
namedRegex: `^${namedParameterizedRoute}(?:/)?$`,
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -773,16 +773,22 @@ const runTests = (isDev = false) => {
|
||||||
],
|
],
|
||||||
dynamicRoutes: [
|
dynamicRoutes: [
|
||||||
{
|
{
|
||||||
|
namedRegex: '^/another/(?<id>[^/]+?)(?:/)?$',
|
||||||
page: '/another/[id]',
|
page: '/another/[id]',
|
||||||
regex: normalizeRegEx('^\\/another\\/([^\\/]+?)(?:\\/)?$'),
|
regex: normalizeRegEx('^\\/another\\/([^\\/]+?)(?:\\/)?$'),
|
||||||
|
routeKeys: ['id'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
namedRegex: '^/api/dynamic/(?<slug>[^/]+?)(?:/)?$',
|
||||||
page: '/api/dynamic/[slug]',
|
page: '/api/dynamic/[slug]',
|
||||||
regex: normalizeRegEx('^\\/api\\/dynamic\\/([^\\/]+?)(?:\\/)?$'),
|
regex: normalizeRegEx('^\\/api\\/dynamic\\/([^\\/]+?)(?:\\/)?$'),
|
||||||
|
routeKeys: ['slug'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
namedRegex: '^/blog/(?<post>[^/]+?)(?:/)?$',
|
||||||
page: '/blog/[post]',
|
page: '/blog/[post]',
|
||||||
regex: normalizeRegEx('^\\/blog\\/([^\\/]+?)(?:\\/)?$'),
|
regex: normalizeRegEx('^\\/blog\\/([^\\/]+?)(?:\\/)?$'),
|
||||||
|
routeKeys: ['post'],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
|
@ -3,15 +3,15 @@ import Link from 'next/link'
|
||||||
const Page = () => (
|
const Page = () => (
|
||||||
<div>
|
<div>
|
||||||
<h3>My blog</h3>
|
<h3>My blog</h3>
|
||||||
<Link href="/[post]" as="/post-1">
|
<Link href="/[name]" as="/post-1">
|
||||||
<a id="view-post-1">View post 1</a>
|
<a id="view-post-1">View post 1</a>
|
||||||
</Link>
|
</Link>
|
||||||
<br />
|
<br />
|
||||||
<Link href="/[post]/comments" as="/post-1/comments">
|
<Link href="/[name]/comments" as="/post-1/comments">
|
||||||
<a id="view-post-1-comments">View post 1 comments</a>
|
<a id="view-post-1-comments">View post 1 comments</a>
|
||||||
</Link>
|
</Link>
|
||||||
<br />
|
<br />
|
||||||
<Link href="/[post]/[comment]" as="/post-1/comment-1">
|
<Link href="/[name]/[comment]" as="/post-1/comment-1">
|
||||||
<a id="view-post-1-comment-1">View comment 1 on post 1</a>
|
<a id="view-post-1-comment-1">View comment 1 on post 1</a>
|
||||||
</Link>
|
</Link>
|
||||||
<br />
|
<br />
|
||||||
|
@ -19,7 +19,7 @@ const Page = () => (
|
||||||
<a id="view-nested-dynamic-cmnt">View comment 123 on blog post 321</a>
|
<a id="view-nested-dynamic-cmnt">View comment 123 on blog post 321</a>
|
||||||
</Link>
|
</Link>
|
||||||
<br />
|
<br />
|
||||||
<Link href="/[post]?fromHome=true" as="/post-1?fromHome=true">
|
<Link href="/[name]?fromHome=true" as="/post-1?fromHome=true">
|
||||||
<a id="view-post-1-with-query">View post 1 with query</a>
|
<a id="view-post-1-with-query">View post 1 with query</a>
|
||||||
</Link>
|
</Link>
|
||||||
<br />
|
<br />
|
||||||
|
|
|
@ -532,78 +532,110 @@ function runTests(dev) {
|
||||||
redirects: [],
|
redirects: [],
|
||||||
dataRoutes: [
|
dataRoutes: [
|
||||||
{
|
{
|
||||||
|
namedDataRouteRegex: `^/_next/data/${escapeRegex(
|
||||||
|
buildId
|
||||||
|
)}/p1/p2/all\\-ssg/(?<rest>.+?)\\.json$`,
|
||||||
dataRouteRegex: normalizeRegEx(
|
dataRouteRegex: normalizeRegEx(
|
||||||
`^\\/_next\\/data\\/${escapeRegex(
|
`^\\/_next\\/data\\/${escapeRegex(
|
||||||
buildId
|
buildId
|
||||||
)}\\/p1\\/p2\\/all\\-ssg\\/(.+?)\\.json$`
|
)}\\/p1\\/p2\\/all\\-ssg\\/(.+?)\\.json$`
|
||||||
),
|
),
|
||||||
page: '/p1/p2/all-ssg/[...rest]',
|
page: '/p1/p2/all-ssg/[...rest]',
|
||||||
|
routeKeys: ['rest'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
namedDataRouteRegex: `^/_next/data/${escapeRegex(
|
||||||
|
buildId
|
||||||
|
)}/p1/p2/nested\\-all\\-ssg/(?<rest>.+?)\\.json$`,
|
||||||
dataRouteRegex: normalizeRegEx(
|
dataRouteRegex: normalizeRegEx(
|
||||||
`^\\/_next\\/data\\/${escapeRegex(
|
`^\\/_next\\/data\\/${escapeRegex(
|
||||||
buildId
|
buildId
|
||||||
)}\\/p1\\/p2\\/nested\\-all\\-ssg\\/(.+?)\\.json$`
|
)}\\/p1\\/p2\\/nested\\-all\\-ssg\\/(.+?)\\.json$`
|
||||||
),
|
),
|
||||||
page: '/p1/p2/nested-all-ssg/[...rest]',
|
page: '/p1/p2/nested-all-ssg/[...rest]',
|
||||||
|
routeKeys: ['rest'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
namedDataRouteRegex: `^/_next/data/${escapeRegex(
|
||||||
|
buildId
|
||||||
|
)}/p1/p2/predefined\\-ssg/(?<rest>.+?)\\.json$`,
|
||||||
dataRouteRegex: normalizeRegEx(
|
dataRouteRegex: normalizeRegEx(
|
||||||
`^\\/_next\\/data\\/${escapeRegex(
|
`^\\/_next\\/data\\/${escapeRegex(
|
||||||
buildId
|
buildId
|
||||||
)}\\/p1\\/p2\\/predefined\\-ssg\\/(.+?)\\.json$`
|
)}\\/p1\\/p2\\/predefined\\-ssg\\/(.+?)\\.json$`
|
||||||
),
|
),
|
||||||
page: '/p1/p2/predefined-ssg/[...rest]',
|
page: '/p1/p2/predefined-ssg/[...rest]',
|
||||||
|
routeKeys: ['rest'],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
dynamicRoutes: [
|
dynamicRoutes: [
|
||||||
{
|
{
|
||||||
|
namedRegex: `^/blog/(?<name>[^/]+?)/comment/(?<id>[^/]+?)(?:/)?$`,
|
||||||
page: '/blog/[name]/comment/[id]',
|
page: '/blog/[name]/comment/[id]',
|
||||||
regex: normalizeRegEx(
|
regex: normalizeRegEx(
|
||||||
'^\\/blog\\/([^\\/]+?)\\/comment\\/([^\\/]+?)(?:\\/)?$'
|
'^\\/blog\\/([^\\/]+?)\\/comment\\/([^\\/]+?)(?:\\/)?$'
|
||||||
),
|
),
|
||||||
|
routeKeys: ['name', 'id'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
namedRegex: `^/on\\-mount/(?<post>[^/]+?)(?:/)?$`,
|
||||||
page: '/on-mount/[post]',
|
page: '/on-mount/[post]',
|
||||||
regex: normalizeRegEx('^\\/on\\-mount\\/([^\\/]+?)(?:\\/)?$'),
|
regex: normalizeRegEx('^\\/on\\-mount\\/([^\\/]+?)(?:\\/)?$'),
|
||||||
|
routeKeys: ['post'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
namedRegex: `^/p1/p2/all\\-ssg/(?<rest>.+?)(?:/)?$`,
|
||||||
page: '/p1/p2/all-ssg/[...rest]',
|
page: '/p1/p2/all-ssg/[...rest]',
|
||||||
regex: normalizeRegEx('^\\/p1\\/p2\\/all\\-ssg\\/(.+?)(?:\\/)?$'),
|
regex: normalizeRegEx('^\\/p1\\/p2\\/all\\-ssg\\/(.+?)(?:\\/)?$'),
|
||||||
|
routeKeys: ['rest'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
namedRegex: `^/p1/p2/all\\-ssr/(?<rest>.+?)(?:/)?$`,
|
||||||
page: '/p1/p2/all-ssr/[...rest]',
|
page: '/p1/p2/all-ssr/[...rest]',
|
||||||
regex: normalizeRegEx('^\\/p1\\/p2\\/all\\-ssr\\/(.+?)(?:\\/)?$'),
|
regex: normalizeRegEx('^\\/p1\\/p2\\/all\\-ssr\\/(.+?)(?:\\/)?$'),
|
||||||
|
routeKeys: ['rest'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
namedRegex: `^/p1/p2/nested\\-all\\-ssg/(?<rest>.+?)(?:/)?$`,
|
||||||
page: '/p1/p2/nested-all-ssg/[...rest]',
|
page: '/p1/p2/nested-all-ssg/[...rest]',
|
||||||
regex: normalizeRegEx(
|
regex: normalizeRegEx(
|
||||||
'^\\/p1\\/p2\\/nested\\-all\\-ssg\\/(.+?)(?:\\/)?$'
|
'^\\/p1\\/p2\\/nested\\-all\\-ssg\\/(.+?)(?:\\/)?$'
|
||||||
),
|
),
|
||||||
|
routeKeys: ['rest'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
namedRegex: `^/p1/p2/predefined\\-ssg/(?<rest>.+?)(?:/)?$`,
|
||||||
page: '/p1/p2/predefined-ssg/[...rest]',
|
page: '/p1/p2/predefined-ssg/[...rest]',
|
||||||
regex: normalizeRegEx(
|
regex: normalizeRegEx(
|
||||||
'^\\/p1\\/p2\\/predefined\\-ssg\\/(.+?)(?:\\/)?$'
|
'^\\/p1\\/p2\\/predefined\\-ssg\\/(.+?)(?:\\/)?$'
|
||||||
),
|
),
|
||||||
|
routeKeys: ['rest'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
namedRegex: `^/(?<name>[^/]+?)(?:/)?$`,
|
||||||
page: '/[name]',
|
page: '/[name]',
|
||||||
regex: normalizeRegEx('^\\/([^\\/]+?)(?:\\/)?$'),
|
regex: normalizeRegEx('^\\/([^\\/]+?)(?:\\/)?$'),
|
||||||
|
routeKeys: ['name'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
namedRegex: `^/(?<name>[^/]+?)/comments(?:/)?$`,
|
||||||
page: '/[name]/comments',
|
page: '/[name]/comments',
|
||||||
regex: normalizeRegEx('^\\/([^\\/]+?)\\/comments(?:\\/)?$'),
|
regex: normalizeRegEx('^\\/([^\\/]+?)\\/comments(?:\\/)?$'),
|
||||||
|
routeKeys: ['name'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
namedRegex: `^/(?<name>[^/]+?)/on\\-mount\\-redir(?:/)?$`,
|
||||||
page: '/[name]/on-mount-redir',
|
page: '/[name]/on-mount-redir',
|
||||||
regex: normalizeRegEx(
|
regex: normalizeRegEx(
|
||||||
'^\\/([^\\/]+?)\\/on\\-mount\\-redir(?:\\/)?$'
|
'^\\/([^\\/]+?)\\/on\\-mount\\-redir(?:\\/)?$'
|
||||||
),
|
),
|
||||||
|
routeKeys: ['name'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
namedRegex: `^/(?<name>[^/]+?)/(?<comment>[^/]+?)(?:/)?$`,
|
||||||
page: '/[name]/[comment]',
|
page: '/[name]/[comment]',
|
||||||
regex: normalizeRegEx('^\\/([^\\/]+?)\\/([^\\/]+?)(?:\\/)?$'),
|
regex: normalizeRegEx('^\\/([^\\/]+?)\\/([^\\/]+?)(?:\\/)?$'),
|
||||||
|
routeKeys: ['name', 'comment'],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
|
@ -47,24 +47,36 @@ const expectedManifestRoutes = () => [
|
||||||
page: '/blog',
|
page: '/blog',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
namedDataRouteRegex: `^/_next/data/${escapeRegex(
|
||||||
|
buildId
|
||||||
|
)}/blog/(?<post>[^/]+?)\\.json$`,
|
||||||
dataRouteRegex: normalizeRegEx(
|
dataRouteRegex: normalizeRegEx(
|
||||||
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/blog\\/([^\\/]+?)\\.json$`
|
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/blog\\/([^\\/]+?)\\.json$`
|
||||||
),
|
),
|
||||||
page: '/blog/[post]',
|
page: '/blog/[post]',
|
||||||
|
routeKeys: ['post'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
namedDataRouteRegex: `^/_next/data/${escapeRegex(
|
||||||
|
buildId
|
||||||
|
)}/blog/(?<post>[^/]+?)/(?<comment>[^/]+?)\\.json$`,
|
||||||
dataRouteRegex: normalizeRegEx(
|
dataRouteRegex: normalizeRegEx(
|
||||||
`^\\/_next\\/data\\/${escapeRegex(
|
`^\\/_next\\/data\\/${escapeRegex(
|
||||||
buildId
|
buildId
|
||||||
)}\\/blog\\/([^\\/]+?)\\/([^\\/]+?)\\.json$`
|
)}\\/blog\\/([^\\/]+?)\\/([^\\/]+?)\\.json$`
|
||||||
),
|
),
|
||||||
page: '/blog/[post]/[comment]',
|
page: '/blog/[post]/[comment]',
|
||||||
|
routeKeys: ['post', 'comment'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
namedDataRouteRegex: `^/_next/data/${escapeRegex(
|
||||||
|
buildId
|
||||||
|
)}/catchall/(?<path>.+?)\\.json$`,
|
||||||
dataRouteRegex: normalizeRegEx(
|
dataRouteRegex: normalizeRegEx(
|
||||||
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/catchall\\/(.+?)\\.json$`
|
`^\\/_next\\/data\\/${escapeRegex(buildId)}\\/catchall\\/(.+?)\\.json$`
|
||||||
),
|
),
|
||||||
page: '/catchall/[...path]',
|
page: '/catchall/[...path]',
|
||||||
|
routeKeys: ['path'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
dataRouteRegex: normalizeRegEx(
|
dataRouteRegex: normalizeRegEx(
|
||||||
|
@ -103,12 +115,16 @@ const expectedManifestRoutes = () => [
|
||||||
page: '/something',
|
page: '/something',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
namedDataRouteRegex: `^/_next/data/${escapeRegex(
|
||||||
|
buildId
|
||||||
|
)}/user/(?<user>[^/]+?)/profile\\.json$`,
|
||||||
dataRouteRegex: normalizeRegEx(
|
dataRouteRegex: normalizeRegEx(
|
||||||
`^\\/_next\\/data\\/${escapeRegex(
|
`^\\/_next\\/data\\/${escapeRegex(
|
||||||
buildId
|
buildId
|
||||||
)}\\/user\\/([^\\/]+?)\\/profile\\.json$`
|
)}\\/user\\/([^\\/]+?)\\/profile\\.json$`
|
||||||
),
|
),
|
||||||
page: '/user/[user]/profile',
|
page: '/user/[user]/profile',
|
||||||
|
routeKeys: ['user'],
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -771,36 +771,52 @@ const runTests = (dev = false, looseMode = false) => {
|
||||||
page: '/blog',
|
page: '/blog',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
namedDataRouteRegex: `^/_next/data/${escapeRegex(
|
||||||
|
buildId
|
||||||
|
)}/blog/(?<post>[^/]+?)\\.json$`,
|
||||||
dataRouteRegex: normalizeRegEx(
|
dataRouteRegex: normalizeRegEx(
|
||||||
`^\\/_next\\/data\\/${escapeRegex(
|
`^\\/_next\\/data\\/${escapeRegex(
|
||||||
buildId
|
buildId
|
||||||
)}\\/blog\\/([^\\/]+?)\\.json$`
|
)}\\/blog\\/([^\\/]+?)\\.json$`
|
||||||
),
|
),
|
||||||
page: '/blog/[post]',
|
page: '/blog/[post]',
|
||||||
|
routeKeys: ['post'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
namedDataRouteRegex: `^/_next/data/${escapeRegex(
|
||||||
|
buildId
|
||||||
|
)}/blog/(?<post>[^/]+?)/(?<comment>[^/]+?)\\.json$`,
|
||||||
dataRouteRegex: normalizeRegEx(
|
dataRouteRegex: normalizeRegEx(
|
||||||
`^\\/_next\\/data\\/${escapeRegex(
|
`^\\/_next\\/data\\/${escapeRegex(
|
||||||
buildId
|
buildId
|
||||||
)}\\/blog\\/([^\\/]+?)\\/([^\\/]+?)\\.json$`
|
)}\\/blog\\/([^\\/]+?)\\/([^\\/]+?)\\.json$`
|
||||||
),
|
),
|
||||||
page: '/blog/[post]/[comment]',
|
page: '/blog/[post]/[comment]',
|
||||||
|
routeKeys: ['post', 'comment'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
namedDataRouteRegex: `^/_next/data/${escapeRegex(
|
||||||
|
buildId
|
||||||
|
)}/catchall/(?<slug>.+?)\\.json$`,
|
||||||
dataRouteRegex: normalizeRegEx(
|
dataRouteRegex: normalizeRegEx(
|
||||||
`^\\/_next\\/data\\/${escapeRegex(
|
`^\\/_next\\/data\\/${escapeRegex(
|
||||||
buildId
|
buildId
|
||||||
)}\\/catchall\\/(.+?)\\.json$`
|
)}\\/catchall\\/(.+?)\\.json$`
|
||||||
),
|
),
|
||||||
page: '/catchall/[...slug]',
|
page: '/catchall/[...slug]',
|
||||||
|
routeKeys: ['slug'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
namedDataRouteRegex: `^/_next/data/${escapeRegex(
|
||||||
|
buildId
|
||||||
|
)}/catchall\\-explicit/(?<slug>.+?)\\.json$`,
|
||||||
dataRouteRegex: normalizeRegEx(
|
dataRouteRegex: normalizeRegEx(
|
||||||
`^\\/_next\\/data\\/${escapeRegex(
|
`^\\/_next\\/data\\/${escapeRegex(
|
||||||
buildId
|
buildId
|
||||||
)}\\/catchall\\-explicit\\/(.+?)\\.json$`
|
)}\\/catchall\\-explicit\\/(.+?)\\.json$`
|
||||||
),
|
),
|
||||||
page: '/catchall-explicit/[...slug]',
|
page: '/catchall-explicit/[...slug]',
|
||||||
|
routeKeys: ['slug'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
dataRouteRegex: normalizeRegEx(
|
dataRouteRegex: normalizeRegEx(
|
||||||
|
@ -811,12 +827,16 @@ const runTests = (dev = false, looseMode = false) => {
|
||||||
page: '/default-revalidate',
|
page: '/default-revalidate',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
namedDataRouteRegex: `^/_next/data/${escapeRegex(
|
||||||
|
buildId
|
||||||
|
)}/non\\-json/(?<p>[^/]+?)\\.json$`,
|
||||||
dataRouteRegex: normalizeRegEx(
|
dataRouteRegex: normalizeRegEx(
|
||||||
`^\\/_next\\/data\\/${escapeRegex(
|
`^\\/_next\\/data\\/${escapeRegex(
|
||||||
buildId
|
buildId
|
||||||
)}\\/non\\-json\\/([^\\/]+?)\\.json$`
|
)}\\/non\\-json\\/([^\\/]+?)\\.json$`
|
||||||
),
|
),
|
||||||
page: '/non-json/[p]',
|
page: '/non-json/[p]',
|
||||||
|
routeKeys: ['p'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
dataRouteRegex: normalizeRegEx(
|
dataRouteRegex: normalizeRegEx(
|
||||||
|
@ -825,12 +845,16 @@ const runTests = (dev = false, looseMode = false) => {
|
||||||
page: '/something',
|
page: '/something',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
namedDataRouteRegex: `^/_next/data/${escapeRegex(
|
||||||
|
buildId
|
||||||
|
)}/user/(?<user>[^/]+?)/profile\\.json$`,
|
||||||
dataRouteRegex: normalizeRegEx(
|
dataRouteRegex: normalizeRegEx(
|
||||||
`^\\/_next\\/data\\/${escapeRegex(
|
`^\\/_next\\/data\\/${escapeRegex(
|
||||||
buildId
|
buildId
|
||||||
)}\\/user\\/([^\\/]+?)\\/profile\\.json$`
|
)}\\/user\\/([^\\/]+?)\\/profile\\.json$`
|
||||||
),
|
),
|
||||||
page: '/user/[user]/profile',
|
page: '/user/[user]/profile',
|
||||||
|
routeKeys: ['user'],
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue