rsnext/test/integration/invalid-href/pages/second.js
JJ Kasper 8e4509caf2 Add warning for invalid href being passed to router (#8231)
* Add warning for bad href being passed to router

* Apply suggestions from code review

Co-Authored-By: Joe Haddad <timer150@gmail.com>

* Inline invalidHref for better code elimination
2019-08-07 10:47:13 -04:00

27 lines
581 B
JavaScript

import Link from 'next/link'
import { useRouter } from 'next/router'
const invalidLink = 'https://google.com/another'
export default () => {
const { query, ...router } = useRouter()
const { method } = query
return method ? (
<a
id='click-me'
onClick={e => {
e.preventDefault()
router[method](invalidLink)
}}
>
invalid link :o
</a>
) : (
// this should throw an error on load since prefetch
// receives the invalid href
<Link href={invalidLink}>
<a id='click-me'>invalid link :o</a>
</Link>
)
}