|
1 | 1 | import { collectFallbackRouteParams } from '../../build/segment-config/app/app-segments'
|
2 | 2 | import type { FallbackRouteParam } from '../../build/static-paths/types'
|
3 | 3 | import type { DynamicParamTypesShort } from '../../shared/lib/app-router-types'
|
| 4 | +import { InvariantError } from '../../shared/lib/invariant-error' |
4 | 5 | import { getRouteMatcher } from '../../shared/lib/router/utils/route-matcher'
|
5 | 6 | import { getRouteRegex } from '../../shared/lib/router/utils/route-regex'
|
6 | 7 | import { dynamicParamTypes } from '../app-render/get-short-dynamic-param-type'
|
@@ -139,24 +140,27 @@ export function getFallbackRouteParams(
|
139 | 140 | continue
|
140 | 141 | }
|
141 | 142 |
|
142 |
| - // If there are no path segments and this is not an optional catchall, |
143 |
| - // we can add it to the fallback route params as the value is unknown. |
144 | 143 | if (
|
145 | 144 | pathSegments.length === 0 &&
|
146 | 145 | fallbackRouteParam.paramType !== 'optional-catchall'
|
147 | 146 | ) {
|
148 |
| - fallbackRouteParams.push(fallbackRouteParam) |
149 |
| - continue |
| 147 | + // We shouldn't be able to match a catchall segment without any path |
| 148 | + // segments if it's not an optional catchall. |
| 149 | + throw new InvariantError( |
| 150 | + `Unexpected empty path segments match for a pathname "${page}" with param "${fallbackRouteParam.paramName}" of type "${fallbackRouteParam.paramType}"` |
| 151 | + ) |
150 | 152 | }
|
151 | 153 |
|
152 | 154 | // The path segments are not empty, and the segments didn't contain any
|
153 | 155 | // unknown params, so we know that this particular fallback route param
|
154 | 156 | // route param is not actually unknown, and is known. We can skip adding
|
155 | 157 | // it to the fallback route params.
|
156 | 158 | } else {
|
157 |
| - // This is some other type of route param, but it wasn't already |
158 |
| - // resolved, so we can add it to the fallback route params. |
159 |
| - fallbackRouteParams.push(fallbackRouteParam) |
| 159 | + // This is some other type of route param that shouldn't get resolved |
| 160 | + // statically. |
| 161 | + throw new InvariantError( |
| 162 | + `Unexpected match for a pathname "${page}" with a param "${fallbackRouteParam.paramName}" of type "${fallbackRouteParam.paramType}"` |
| 163 | + ) |
160 | 164 | }
|
161 | 165 | } else if (unknownParamKeys.has(fallbackRouteParam.paramName)) {
|
162 | 166 | // As this is a non-parallel route segment, and it exists in the unknown
|
|
0 commit comments