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

Add test for link back to original page #41297

Merged
merged 5 commits into from Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions packages/next/client/components/reducer.ts
Expand Up @@ -471,11 +471,16 @@ function shouldHardNavigate(
string
]

// If dynamic parameter in tree doesn't match up with segment path a hard navigation is triggered.
if (Array.isArray(currentSegment) && !matchSegment(currentSegment, segment)) {
return true
}
// Check if current segment matches the existing segment.
if (!matchSegment(currentSegment, segment)) {
// If dynamic parameter in tree doesn't match up with segment path a hard navigation is triggered.
if (Array.isArray(currentSegment)) {
return true
}

// If the existing segment did not match soft navigation is triggered.
return false
}
const lastSegment = flightSegmentPath.length <= 2

if (lastSegment) {
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/app-dir/app/app/linking/about/page.js
@@ -0,0 +1,3 @@
export default function AboutPage() {
return <p id="about-page">About page</p>
}
15 changes: 15 additions & 0 deletions test/e2e/app-dir/app/app/linking/layout.js
@@ -0,0 +1,15 @@
import Link from 'next/link'

export default function Layout({ children }) {
return (
<>
<header>
<nav>
<Link href="/linking">Home</Link>
<Link href="/linking/about">About</Link>
</nav>
</header>
{children}
</>
)
}
3 changes: 3 additions & 0 deletions test/e2e/app-dir/app/app/linking/page.js
@@ -0,0 +1,3 @@
export default function Page() {
return <p id="home-page">Home page</p>
}
18 changes: 18 additions & 0 deletions test/e2e/app-dir/index.test.ts
Expand Up @@ -1570,6 +1570,24 @@ describe('app dir', () => {
.text()
).toBe(`hello from app/dashboard/deployments/info/[id]. ID is: 123`)
})
it('should handle next/link back to initially loaded page', async () => {
const browser = await webdriver(next.url, '/linking/about')
expect(
await browser
.elementByCss('a[href="/linking"]')
.click()
.waitForElementByCss('#home-page')
.text()
).toBe(`Home page`)

expect(
await browser
.elementByCss('a[href="/linking/about"]')
.click()
.waitForElementByCss('#about-page')
.text()
).toBe(`About page`)
})
})

describe('not-found', () => {
Expand Down