Skip to content

Commit

Permalink
fix renderKind
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding committed Apr 25, 2023
1 parent 90c2a32 commit 5c6bc94
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/next/src/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1380,27 +1380,31 @@ export default class NextNodeServer extends BaseServer {

if (this.isRouterWorker) {
let page = pathname
let matched = false
let matchedExistingRoute = false

if (!(await this.hasPage(page))) {
for (const route of this.dynamicRoutes || []) {
if (route.match(pathname)) {
page = route.page
matched = true
matchedExistingRoute = true
break
}
}
} else {
matched = true
matchedExistingRoute = true
}

let renderKind: 'app' | 'pages' = this.appPathRoutes?.[page]
? 'app'
: 'pages'
let renderKind: 'app' | 'pages' =
this.appPathRoutes?.[page] ||
// Possible that it's a dynamic app route or behind routing rules
// such as i18n. In that case, we need to check the route kind directly.
match?.definition.kind === RouteKind.APP_PAGE
? 'app'
: 'pages'

// Handle app dir's /not-found feature: for 404 pages, they should be
// routed to the app renderer.
if (!matched && this.appPathRoutes) {
if (!matchedExistingRoute && this.appPathRoutes) {
if (
this.appPathRoutes[
this.renderOpts.dev ? '/not-found' : '/_not-found'
Expand Down

0 comments on commit 5c6bc94

Please sign in to comment.