Skip to content

Commit

Permalink
fix: link parser
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Apr 21, 2024
1 parent d8595b8 commit 3b7fcfd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 2 additions & 5 deletions src/app/(app)/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ export default ({ error, reset }: any) => {
return (
<NormalContainer>
<div className="flex min-h-[calc(100vh-10rem)] flex-col center">
<h2 className="mb-5">
<p>
服务端渲染页面时出现了错误,可能是 Next.js 服务访问 API
数据发生异常。请刷新重试。
</p>
<h2 className="mb-5 text-center">
<p>渲染页面时出现了错误</p>
<p>
多次出现错误请联系开发者 <a href="mailto:i@innei.in">Innei</a>
,谢谢!
Expand Down
11 changes: 10 additions & 1 deletion src/components/ui/link/MLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ export const MLink: FC<{
if (isServerSide) return false
const locateUrl = new URL(location.href)

const toUrlParser = new URL(href)
let toUrlParser
try {
toUrlParser = new URL(href)
} catch {
try {
toUrlParser = new URL(href, location.origin)
} catch {
return false
}
}
return (
toUrlParser.host === locateUrl.host ||
(process.env.NODE_ENV === 'development' &&
Expand Down

0 comments on commit 3b7fcfd

Please sign in to comment.