Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(router): allow relative navigation from index pages #33084

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions test/integration/client-navigation/pages/nav/relative/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Link from 'next/link'

export default function Relative() {
return (
<div id="relative">
On relative index
<Link href="./relative-1">To relative 1</Link>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Link from 'next/link'

export default function Relative1() {
return (
<div id="relative-1">
On relative 1
<Link href="./relative-2">
<a>To relative 2</a>
</Link>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useRouter } from 'next/router'

export default function Relative2() {
const router = useRouter()
return (
<div id="relative-2">
On relative 2
<button
onClick={(e) => {
e.preventDefault()
router.push('.')
}}
>
To relative index
</button>
</div>
)
}
22 changes: 22 additions & 0 deletions test/integration/client-navigation/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,28 @@ describe('Client Navigation', () => {
expect(value).toBe(false)
})

it('should navigate to paths relative to the current page', async () => {
const browser = await webdriver(context.appPort, '/nav/relative')
await browser.waitForElementByCss('body', 500)
let page

await browser.elementByCss('a').click()
page = await browser.elementByCss('body').text()
expect(page).toMatch('On relative 1')
await browser.elementByCss('a').click()

browser.waitForElementByCss('#relative-2', 500)
page = await browser.elementByCss('body').text()
expect(page).toMatch(/On relative 2/)

await browser.elementByCss('button').click()
browser.waitForElementByCss('#relative', 500)
page = await browser.elementByCss('body').text()
expect(page).toMatch(/On relative index/)

await browser.close()
})

renderingSuite(
(p, q) => renderViaHTTP(context.appPort, p, q),
(p, q) => fetchViaHTTP(context.appPort, p, q),
Expand Down