sakai-react icon indicating copy to clipboard operation
sakai-react copied to clipboard

Example using nextjs 13.4 App Router

Open BDive opened this issue 2 years ago • 12 comments

Hi, An example using the nextjs 13.4 App Router would be great - running into multiple compile and runtime issues porting page to app router.

Thanks

BDive avatar May 06 '23 15:05 BDive

+1

getdir avatar May 12 '23 21:05 getdir

+1 same here! any updates?

Ali-Aref avatar May 14 '23 06:05 Ali-Aref

+1

accountsware avatar May 24 '23 13:05 accountsware

+1 same here! any updates?

yusrandi avatar Jun 01 '23 04:06 yusrandi

+1

dzabdelhak avatar Jun 02 '23 08:06 dzabdelhak

+1 same here! any updates?

nestorzamili avatar Jun 06 '23 14:06 nestorzamili

Same here. Is there any update??

juanlopez87 avatar Jun 13 '23 15:06 juanlopez87

There is a guy that forked Sakai and did part of the adaptation to Nextjs 13.4: https://github.com/buraksaglam089/sakai-react

palerique avatar Jun 23 '23 14:06 palerique

Same here

Vicidevs avatar Jul 06 '23 20:07 Vicidevs

+1

thomassonobe avatar Jul 24 '23 14:07 thomassonobe

I used this as an inspiration : https://nextjs.org/docs/app/api-reference/components/link#href-required and https://nextjs.org/docs/app/api-reference/file-conventions/page#params-optional

Folders need to be defined :

pages- folder
  details - folder
      [slug] - folder
          page.tsx -file - detailed element page - that is received dynamically based on params
       page.tsx - file - main details page

Paths in browser desired:

localhost:3000/pages/details
localhost:3000/pages/details/1

Code for main details page where we add some links :

'use client';
import Link from 'next/link';
import { useRouter } from 'next/navigation'

export default function Home() {
    return (
      <>
        <header>
          <h1>Home</h1>
        </header>
        <main>
          <h2>All Posts</h2>
          <ol>
              <li key="1">
                <Link href={`/pages/details/my-first-post`}>
                  un link catre details / 1
                </Link>
              </li>
              <li key="2">
                <Link href={`/pages/details/my-second-post`}>
                  un link catre details / 2
                </Link>
              </li>
          </ol>
        </main>
      </>
    );
  }

Detail element page - coming dynamically from slug attr in params:

'use client';
import Link from 'next/link';
import { useRouter } from 'next/navigation'

export default function Details({ params, searchParams }: {
    params: { slug: string }
    searchParams: { [key: string]: string | string[] | undefined }
  }) {
    const router = useRouter();
    console.log(params);
    console.log(searchParams);
    return (
        <>
        <header>
            <Link href="/">
            Home
            </Link>
        </header>
        <main>
            <article>
            <h1>We received param.slug=`{params.slug}`</h1>
            <p>this can be anything</p>
            </article>
        </main>
        </>
    );
}

I hope this helps !

CretuCristianIonut avatar Oct 31 '23 10:10 CretuCristianIonut