未验证 提交 20a4928b 编写于 作者: J Jan Potoms 提交者: GitHub

remove unneeded error (#16636)

This is not needed anymore since absolute urls are supported.
Also added an extra test for `mailto:` urls
上级 5bda90f8
......@@ -115,23 +115,6 @@ function prepareUrlAs(router: NextRouter, url: Url, as: Url) {
}
}
function tryParseRelativeUrl(
url: string
): null | ReturnType<typeof parseRelativeUrl> {
try {
return parseRelativeUrl(url)
} catch (err) {
if (process.env.NODE_ENV !== 'production') {
setTimeout(() => {
throw new Error(
`Invalid href passed to router: ${url} https://err.sh/vercel/next.js/invalid-href-passed`
)
}, 0)
}
return null
}
}
export type BaseRouter = {
route: string
pathname: string
......@@ -503,9 +486,7 @@ export default class Router implements BaseRouter {
const pages = await this.pageLoader.getPageList()
const { __rewrites: rewrites } = await this.pageLoader.promisedBuildManifest
let parsed = tryParseRelativeUrl(url)
if (!parsed) return false
let parsed = parseRelativeUrl(url)
let { pathname, searchParams } = parsed
......@@ -899,9 +880,7 @@ export default class Router implements BaseRouter {
asPath: string = url,
options: PrefetchOptions = {}
): Promise<void> {
let parsed = tryParseRelativeUrl(url)
if (!parsed) return
let parsed = parseRelativeUrl(url)
let { pathname } = parsed
......
......@@ -135,6 +135,12 @@ describe('Invalid hrefs', () => {
const $ = cheerio.load(await res.text())
expect($('#click-me').attr('href')).toBe('https://')
})
it('renders a link with mailto: href', async () => {
const res = await fetchViaHTTP(appPort, '/first')
const $ = cheerio.load(await res.text())
expect($('#click-me').attr('href')).toBe('mailto:idk@idk.com')
})
})
describe('dev mode', () => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册