Skip to content

Commit ad7e01a

Browse files
authored
fix(nextjs): Fix router compat when use client is used (#7951)
1 parent 072c650 commit ad7e01a

File tree

2 files changed

+33
-1
lines changed
  • packages/nextjs/src/pages-router
  • playground/nextjs/src/app/inbox-client

2 files changed

+33
-1
lines changed

packages/nextjs/src/pages-router/Inbox.tsx

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
'use client';
22

33
import { InboxProps, Inbox as RInbox } from '@novu/react';
4-
import { useRouter } from 'next/router';
4+
import { useRouter as useAppRouter } from 'next/navigation';
5+
import { useRouter } from 'next/compat/router';
6+
7+
function AppRouterInbox(props: InboxProps) {
8+
const router = useAppRouter();
9+
10+
return <RInbox routerPush={router.push} {...props} />;
11+
}
512

613
export function Inbox(props: InboxProps) {
714
const router = useRouter();
815

16+
if (!router) {
17+
return <AppRouterInbox {...props} />;
18+
}
19+
920
return <RInbox routerPush={router.push} {...props} />;
1021
}
1122

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use client';
2+
3+
import { novuConfig } from '@/utils/config';
4+
import { Inbox, Notifications, Preferences } from '@novu/nextjs';
5+
6+
export default function InboxPage() {
7+
return (
8+
<>
9+
<h1>Hello from Inbox page</h1>
10+
<div className="flex flex-col gap-4">
11+
<h1>App Router</h1>
12+
<Inbox {...novuConfig}>
13+
<h2>My custom Inbox</h2>
14+
<Preferences />
15+
<Notifications />
16+
</Inbox>
17+
<Inbox {...novuConfig} />
18+
</div>
19+
</>
20+
);
21+
}

0 commit comments

Comments
 (0)