Skip to content

Commit

Permalink
Same problem with other approach
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot committed Jul 2, 2020
1 parent 657ea99 commit b8db626
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/next/lib/load-custom-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,19 +350,19 @@ export default async function loadCustomRoutes(
? [
{
source: '/:path*/:file.:ext/',
destination: config.basePath + '/:path*/:file.:ext',
destination: '/:path*/:file.:ext',
permanent: true,
},
{
source: '/:path*/:notfile([^/.]+)',
destination: config.basePath + '/:path*/:notfile/',
destination: '/:path*/:notfile/',
permanent: true,
},
]
: [
{
source: '/:path+/',
destination: config.basePath + '/:path+',
destination: '/:path+',
permanent: true,
},
])
Expand Down
9 changes: 8 additions & 1 deletion packages/next/next-server/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ export default class Server {
this.renderOpts.assetPrefix = prefix ? prefix.replace(/\/$/, '') : ''
}

private addBasePath(path: string): string {
const { basePath } = this.nextConfig
return basePath ? (path === '/' ? basePath : basePath + path) : path
}

// Backwards compatibility
public async prepare(): Promise<void> {}

Expand Down Expand Up @@ -509,7 +514,9 @@ export default class Server {
params,
parsedUrl.query
)
const updatedDestination = formatUrl(parsedDestination)
const updatedDestination = this.addBasePath(
formatUrl(parsedDestination)
)

res.setHeader('Location', updatedDestination)
res.statusCode = getRedirectStatus(redirectRoute as Redirect)
Expand Down

0 comments on commit b8db626

Please sign in to comment.