-
Notifications
You must be signed in to change notification settings - Fork 27.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
notify component when route hash changes (#13894)
This resolves #13659
- Loading branch information
Showing
3 changed files
with
68 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 51 additions & 46 deletions
97
test/integration/client-navigation/pages/nav/hash-changes.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,58 @@ | ||
import React, { Component } from 'react' | ||
import React from 'react' | ||
import Link from 'next/link' | ||
import { useRouter } from 'next/router' | ||
|
||
let count = 0 | ||
|
||
export default class SelfReload extends Component { | ||
static getInitialProps({ res }) { | ||
if (res) return { count: 0 } | ||
count += 1 | ||
const HashChanges = ({ count }) => { | ||
const router = useRouter() | ||
|
||
return { count } | ||
} | ||
return ( | ||
<div id="hash-changes-page"> | ||
<Link href="#via-link"> | ||
<a id="via-link">Via Link</a> | ||
</Link> | ||
<a href="#via-a" id="via-a"> | ||
Via A | ||
</a> | ||
<Link href="/nav/hash-changes"> | ||
<a id="page-url">Page URL</a> | ||
</Link> | ||
<Link href="#"> | ||
<a id="via-empty-hash">Via Empty Hash</a> | ||
</Link> | ||
<Link href="#item-400"> | ||
<a id="scroll-to-item-400">Go to item 400</a> | ||
</Link> | ||
<Link href="#name-item-400"> | ||
<a id="scroll-to-name-item-400">Go to name item 400</a> | ||
</Link> | ||
<p>COUNT: {count}</p> | ||
{Array.from({ length: 500 }, (x, i) => i + 1).map((i) => { | ||
return ( | ||
<div key={`item-${i}`} id={`item-${i}`}> | ||
{i} | ||
</div> | ||
) | ||
})} | ||
{Array.from({ length: 500 }, (x, i) => i + 1).map((i) => { | ||
return ( | ||
<div key={`item-${i}`} name={`name-item-${i}`}> | ||
{i} | ||
</div> | ||
) | ||
})} | ||
<div id="asPath">ASPATH: {router.asPath}</div> | ||
<div id="pathname">PATHNAME: {router.pathname}</div> | ||
</div> | ||
) | ||
} | ||
|
||
HashChanges.getInitialProps = ({ res }) => { | ||
if (res) return { count: 0 } | ||
count += 1 | ||
|
||
render() { | ||
return ( | ||
<div id="hash-changes-page"> | ||
<Link href="#via-link"> | ||
<a id="via-link">Via Link</a> | ||
</Link> | ||
<a href="#via-a" id="via-a"> | ||
Via A | ||
</a> | ||
<Link href="/nav/hash-changes"> | ||
<a id="page-url">Page URL</a> | ||
</Link> | ||
<Link href="#"> | ||
<a id="via-empty-hash">Via Empty Hash</a> | ||
</Link> | ||
<Link href="#item-400"> | ||
<a id="scroll-to-item-400">Go to item 400</a> | ||
</Link> | ||
<Link href="#name-item-400"> | ||
<a id="scroll-to-name-item-400">Go to name item 400</a> | ||
</Link> | ||
<p>COUNT: {this.props.count}</p> | ||
{Array.from({ length: 500 }, (x, i) => i + 1).map((i) => { | ||
return ( | ||
<div key={`item-${i}`} id={`item-${i}`}> | ||
{i} | ||
</div> | ||
) | ||
})} | ||
{Array.from({ length: 500 }, (x, i) => i + 1).map((i) => { | ||
return ( | ||
<div key={`item-${i}`} name={`name-item-${i}`}> | ||
{i} | ||
</div> | ||
) | ||
})} | ||
</div> | ||
) | ||
} | ||
return { count } | ||
} | ||
|
||
export default HashChanges |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters