Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
1d0e7a8a
Unverified
Commit
1d0e7a8a
authored
Jun 29, 2020
by
Joe Haddad
Committed by
GitHub
Jun 29, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable Optional Catch-All by Default (#14687)
Closes #14682
parent
f12a9f92
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
7 additions
and
53 deletions
+7
-53
dynamic-api-routes.md
docs/api-routes/dynamic-api-routes.md
+0
-3
dynamic-routes.md
docs/routing/dynamic-routes.md
+0
-3
index.ts
packages/next/build/index.ts
+1
-11
config.ts
packages/next/next-server/server/config.ts
+1
-3
next-dev-server.ts
packages/next/server/next-dev-server.ts
+0
-15
next.config.js
test/integration/dynamic-optional-routing/next.config.js
+1
-1
index.test.js
test/integration/dynamic-optional-routing/test/index.test.js
+2
-5
next.config.js
test/integration/prerender/next.config.js
+0
-3
index.test.js
test/integration/prerender/test/index.test.js
+2
-9
No files found.
docs/api-routes/dynamic-api-routes.md
View file @
1d0e7a8a
...
...
@@ -82,9 +82,6 @@ Now, a request to `/api/post/a/b/c` will respond with the text: `Post: a, b, c`.
### Optional catch all API routes
> **Warning**: This feature is **experimental and may not work as expected**.
> You must enable the `optionalCatchAll` experimental option to try it.
Catch all routes can be made optional by including the parameter in double brackets (
`[[...slug]]`
).
For example,
`pages/api/post/[[...slug]].js`
will match
`/api/post`
,
`/api/post/a`
,
`/api/post/a/b`
, and so on.
...
...
docs/routing/dynamic-routes.md
View file @
1d0e7a8a
...
...
@@ -87,9 +87,6 @@ And in the case of `/post/a/b`, and any other matching path, new parameters will
### Optional catch all routes
> **Warning**: This feature is **experimental and may not work as expected**.
> You must enable the `optionalCatchAll` experimental option to try it.
Catch all routes can be made optional by including the parameter in double brackets (
`[[...slug]]`
).
For example,
`pages/post/[[...slug]].js`
will match
`/post`
,
`/post/a`
,
`/post/a/b`
, and so on.
...
...
packages/next/build/index.ts
View file @
1d0e7a8a
...
...
@@ -47,6 +47,7 @@ import loadConfig, {
import
{
BuildManifest
}
from
'../next-server/server/get-page-files'
import
'../next-server/server/node-polyfill-fetch'
import
{
normalizePagePath
}
from
'../next-server/server/normalize-page-path'
import
{
getPagePath
}
from
'../next-server/server/require'
import
*
as
ciEnvironment
from
'../telemetry/ci-info'
import
{
eventBuildCompleted
,
...
...
@@ -73,7 +74,6 @@ import {
import
getBaseWebpackConfig
from
'./webpack-config'
import
{
PagesManifest
}
from
'./webpack/plugins/pages-manifest-plugin'
import
{
writeBuildId
}
from
'./write-build-id'
import
{
getPagePath
}
from
'../next-server/server/require'
const
staticCheckWorker
=
require
.
resolve
(
'./utils'
)
export
type
SsgRoute
=
{
...
...
@@ -277,16 +277,6 @@ export default async function build(dir: string, conf = null): Promise<void> {
}
}
const
firstOptionalCatchAllPage
=
pageKeys
.
find
((
f
)
=>
/
\[\[\.{3}[^\]
[
/]
*
\]\]
/
.
test
(
f
))
??
null
if
(
config
.
experimental
?.
optionalCatchAll
!==
true
&&
firstOptionalCatchAllPage
)
{
const
msg
=
`Optional catch-all routes are currently experimental and cannot be used by default ("
${
firstOptionalCatchAllPage
}
").`
throw
new
Error
(
msg
)
}
const
routesManifestPath
=
path
.
join
(
distDir
,
ROUTES_MANIFEST
)
const
routesManifest
:
any
=
{
version
:
3
,
...
...
packages/next/next-server/server/config.ts
View file @
1d0e7a8a
...
...
@@ -2,10 +2,9 @@ import chalk from 'next/dist/compiled/chalk'
import
findUp
from
'next/dist/compiled/find-up'
import
os
from
'os'
import
{
basename
,
extname
}
from
'path'
import
*
as
Log
from
'../../build/output/log'
import
{
CONFIG_FILE
}
from
'../lib/constants'
import
{
execOnce
}
from
'../lib/utils'
import
*
as
Log
from
'../../build/output/log'
const
targets
=
[
'server'
,
'serverless'
,
'experimental-serverless-trace'
]
const
reactModes
=
[
'legacy'
,
'blocking'
,
'concurrent'
]
...
...
@@ -54,7 +53,6 @@ const defaultConfig: { [key: string]: any } = {
workerThreads
:
false
,
pageEnv
:
false
,
productionBrowserSourceMaps
:
false
,
optionalCatchAll
:
false
,
},
future
:
{
excludeDefaultMomentLocales
:
false
,
...
...
packages/next/server/next-dev-server.ts
View file @
1d0e7a8a
...
...
@@ -210,21 +210,6 @@ export default class DevServer extends Server {
match
:
getRouteMatcher
(
getRouteRegex
(
page
)),
}))
const
firstOptionalCatchAllPage
=
this
.
dynamicRoutes
.
find
((
f
)
=>
/
\[\[\.{3}[^\]
[
/]
*
\]\]
/
.
test
(
f
.
page
))
?.
page
??
null
if
(
this
.
nextConfig
.
experimental
?.
optionalCatchAll
!==
true
&&
firstOptionalCatchAllPage
)
{
const
msg
=
`Optional catch-all routes are currently experimental and cannot be used by default ("
${
firstOptionalCatchAllPage
}
").`
if
(
resolved
)
{
console
.
warn
(
msg
)
}
else
{
throw
new
Error
(
msg
)
}
}
this
.
router
.
setDynamicRoutes
(
this
.
dynamicRoutes
)
if
(
!
resolved
)
{
...
...
test/integration/dynamic-optional-routing/next.config.js
View file @
1d0e7a8a
module
.
exports
=
{
experimental
:
{
optionalCatchAll
:
true
}
}
module
.
exports
=
{}
test/integration/dynamic-optional-routing/test/index.test.js
View file @
1d0e7a8a
...
...
@@ -261,10 +261,7 @@ describe('Dynamic Optional Routing', () => {
const
curConfig
=
await
fs
.
readFile
(
nextConfig
,
'utf8'
)
if
(
curConfig
.
includes
(
'target'
))
{
await
fs
.
writeFile
(
nextConfig
,
`module.exports = { experimental: { optionalCatchAll: true } }`
)
await
fs
.
writeFile
(
nextConfig
,
`module.exports = {}`
)
}
await
nextBuild
(
appDir
)
...
...
@@ -323,7 +320,7 @@ describe('Dynamic Optional Routing', () => {
origNextConfig
=
await
fs
.
readFile
(
nextConfig
,
'utf8'
)
await
fs
.
writeFile
(
nextConfig
,
`module.exports = { target: 'serverless'
, experimental: { optionalCatchAll: true }
}`
`module.exports = { target: 'serverless' }`
)
await
nextBuild
(
appDir
)
...
...
test/integration/prerender/next.config.js
View file @
1d0e7a8a
module
.
exports
=
{
experimental
:
{
optionalCatchAll
:
true
,
},
rewrites
()
{
return
[
{
...
...
test/integration/prerender/test/index.test.js
View file @
1d0e7a8a
...
...
@@ -1330,9 +1330,6 @@ describe('SSG Prerender', () => {
nextConfig
,
`
module.exports = {
experimental: {
optionalCatchAll: true,
},
rewrites() {
return [
{
...
...
@@ -1372,7 +1369,7 @@ describe('SSG Prerender', () => {
nextConfig
,
// we set cpus to 1 so that we make sure the requests
// aren't being cached at the jest-worker level
`module.exports = { experimental: {
optionalCatchAll: true,
cpus: 1 } }`
,
`module.exports = { experimental: { cpus: 1 } }`
,
'utf8'
)
await
fs
.
remove
(
join
(
appDir
,
'.next'
))
...
...
@@ -1439,9 +1436,6 @@ describe('SSG Prerender', () => {
nextConfig
,
`module.exports = {
target: 'serverless',
experimental: {
optionalCatchAll: true,
},
rewrites() {
return [
{
...
...
@@ -1550,7 +1544,7 @@ describe('SSG Prerender', () => {
origConfig
=
await
fs
.
readFile
(
nextConfig
,
'utf8'
)
await
fs
.
writeFile
(
nextConfig
,
`module.exports = { target: 'experimental-serverless-trace'
, experimental: { optionalCatchAll: true }
}`
,
`module.exports = { target: 'experimental-serverless-trace' }`
,
'utf8'
)
await
fs
.
writeFile
(
...
...
@@ -1637,7 +1631,6 @@ describe('SSG Prerender', () => {
await
fs
.
writeFile
(
nextConfig
,
`module.exports = {
experimental: { optionalCatchAll: true },
exportTrailingSlash: true,
exportPathMap: function(defaultPathMap) {
if (defaultPathMap['/blog/[post]']) {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment