12aa56123b
My last PR (#26205) made the hash change events not fire when in i18n was enabled, as seen in #26853. This PR fixes that and adds a test for this case. fixes #26853 ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes
50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
import Link from 'next/link'
|
|
import { useRouter } from 'next/router'
|
|
import { useEffect } from 'react'
|
|
|
|
export default function Page(props) {
|
|
const router = useRouter()
|
|
|
|
useEffect(() => {
|
|
window.hashChangeStart = 'no'
|
|
window.hashChangeComplete = 'no'
|
|
const hashChangeStart = () => {
|
|
window.hashChangeStart = 'yes'
|
|
}
|
|
const hashChangeComplete = () => {
|
|
window.hashChangeComplete = 'yes'
|
|
}
|
|
|
|
router.events.on('hashChangeStart', hashChangeStart)
|
|
router.events.on('hashChangeComplete', hashChangeComplete)
|
|
|
|
return () => {
|
|
router.events.off('hashChangeStart', hashChangeStart)
|
|
router.events.off('hashChangeComplete', hashChangeComplete)
|
|
}
|
|
}, [router.events])
|
|
|
|
return (
|
|
<>
|
|
<p id="props-locale">{props.locale}</p>
|
|
<p id="router-locale">{router.locale}</p>
|
|
<Link
|
|
href={{ pathname: router.pathname, query: router.query, hash: '#hash' }}
|
|
locale={router.locale === 'fr' ? 'en' : 'fr'}
|
|
>
|
|
<a id="change-locale">Change Locale</a>
|
|
</Link>
|
|
<Link href={{ hash: '#newhash' }}>
|
|
<a id="hash-change">Hash Change</a>
|
|
</Link>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export const getStaticProps = async ({ locale }) => {
|
|
return {
|
|
props: {
|
|
locale,
|
|
},
|
|
}
|
|
}
|