Skip to content

Commit

Permalink
Ensure client filter with basePath is correct
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Jan 12, 2024
1 parent d98b5a5 commit afd7330
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/next/src/shared/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1319,13 +1319,6 @@ export default class Router implements BaseRouter {
let parsed = parseRelativeUrl(url)
let { pathname, query } = parsed

// if we detected the path as app route during prefetching
// trigger hard navigation
if ((this.components[pathname] as any)?.__appRouter) {
handleHardNavigation({ url: as, router: this })
return new Promise(() => {})
}

// The build manifest needs to be loaded before auto-static dynamic pages
// get their query parameters to allow ensuring they can be parsed properly
// when rewritten to
Expand Down Expand Up @@ -1366,6 +1359,13 @@ export default class Router implements BaseRouter {
let route = removeTrailingSlash(pathname)
const parsedAsPathname = as.startsWith('/') && parseRelativeUrl(as).pathname

// if we detected the path as app route during prefetching
// trigger hard navigation
if ((this.components[pathname] as any)?.__appRouter) {
handleHardNavigation({ url: as, router: this })
return new Promise(() => {})
}

const isMiddlewareRewrite = !!(
parsedAsPathname &&
route !== parsedAsPathname &&
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/app-dir/app-basepath/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ createNextDescribe(
},
},
({ next }) => {
it('should successfully hard navigate from pages -> app', async () => {
const browser = await next.browser('/base/pages-path')
await browser.elementByCss('#to-another').click()
await browser.waitForElementByCss('#page-2')
})

it('should support `basePath`', async () => {
const html = await next.render('/base')
expect(html).toContain('<h1>Test Page</h1>')
Expand Down
12 changes: 12 additions & 0 deletions test/e2e/app-dir/app-basepath/pages/pages-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Link from 'next/link'

export default function Page() {
return (
<>
<p>pages-path</p>
<Link href="/another" id="to-another">
to /another
</Link>
</>
)
}
7 changes: 7 additions & 0 deletions test/e2e/app-dir/app/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ createNextDescribe(
})
}

it('should successfully hard navigate from pages -> app', async () => {
const browser = await next.browser('/')

await browser.elementByCss('a').click()
await browser.waitForElementByCss('#from-dashboard')
})

it('should encode chunk path correctly', async () => {
await next.fetch('/dynamic-client/first/second')
const browser = await next.browser('/')
Expand Down

0 comments on commit afd7330

Please sign in to comment.