Skip to content

Commit 2ea858a

Browse files
authored
fix: ignore getStaticPaths() for routes with no url params
1 parent 50ef2ac commit 2ea858a

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

packages/root/src/render/router.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ export class Router {
109109

110110
const urlPaths: Array<{urlPath: string; params: Record<string, string>}> =
111111
[];
112-
if (routeModule.getStaticPaths) {
112+
const pathHasParams = testPathHasParams(urlPathFormat);
113+
if (pathHasParams && routeModule.getStaticPaths) {
113114
const staticPaths = await routeModule.getStaticPaths({
114115
rootConfig: this.rootConfig,
115116
});
@@ -120,9 +121,9 @@ export class Router {
120121
urlPathFormat,
121122
pathParams.params || {}
122123
);
123-
if (pathContainsPlaceholders(urlPath)) {
124+
if (testPathHasParams(urlPath)) {
124125
console.warn(
125-
`path contains placeholders: ${urlPathFormat}, double check getStaticPaths() and ensure all params are returned. more info: https://rootjs.dev/guide/routes#getStaticPaths`
126+
`path contains params: ${urlPathFormat}, double check getStaticPaths() and ensure all params are returned. more info: https://rootjs.dev/guide/routes#getStaticPaths`
126127
);
127128
} else {
128129
urlPaths.push({
@@ -135,22 +136,22 @@ export class Router {
135136
}
136137
} else if (
137138
routeModule.getStaticProps &&
138-
!pathContainsPlaceholders(urlPathFormat)
139+
!pathHasParams
139140
) {
140141
urlPaths.push({urlPath: normalizeUrlPath(urlPathFormat), params: {}});
141142
} else if (
142143
!routeModule.handle &&
143-
!pathContainsPlaceholders(urlPathFormat)
144+
!pathHasParams
144145
) {
145146
urlPaths.push({urlPath: normalizeUrlPath(urlPathFormat), params: {}});
146147
} else if (
147-
pathContainsPlaceholders(urlPathFormat) &&
148+
pathHasParams &&
148149
!routeModule.handle &&
149150
!routeModule.getStaticPaths
150151
) {
151152
console.warn(
152153
[
153-
`warning: path contains placeholders: ${urlPathFormat}.`,
154+
`warning: path contains params: ${urlPathFormat}.`,
154155
`define either ssg getStaticPaths() or ssr handle() for route: ${route.src}.`,
155156
'more info: https://rootjs.dev/guide/routes',
156157
].join('\n')
@@ -207,7 +208,7 @@ export function normalizeUrlPath(
207208
return urlPath;
208209
}
209210

210-
function pathContainsPlaceholders(urlPath: string) {
211+
function testPathHasParams(urlPath: string) {
211212
const segments = urlPath.split('/');
212213
return segments.some((segment) => {
213214
return segment.startsWith('[') && segment.endsWith(']');

0 commit comments

Comments
 (0)