home2 ๊ฒŒ์‹œํŒ Next.js ๊ฒŒ์‹œํŒ not-found.js ๊ด€๋ จ

not-found.js ๊ด€๋ จ

  • ์ด ์ฃผ์ œ์—๋Š” 1๊ฐœ ๋‹ต๋ณ€, 2๋ช… ์ฐธ์—ฌ๊ฐ€ ์žˆ์œผ๋ฉฐ codingapple๊ฐ€ 2 ๋…„, 6 ์›” ์ „์— ์ „์— ๋งˆ์ง€๋ง‰์œผ๋กœ ์—…๋ฐ์ดํŠธํ–ˆ์Šต๋‹ˆ๋‹ค.
2 ๊ธ€ ๋ณด์ž„ - 1 ์—์„œ 2 ๊นŒ์ง€ (์ด 2 ์ค‘์—์„œ)
  • ๊ธ€์“ด์ด
    ๊ธ€
  • #93540

    ์ดํ˜„์„ฑ
    ์ฐธ๊ฐ€์ž
    url์—์„œ ๊ฒŒ์‹œ๊ธ€ id๋ฅผ ์กฐ์ž‘ํ•ด ์ผ๋ถ€๋Ÿฌ 404 ํŽ˜์ด์ง€๋ฅผ ์œ ๋„ํ•  ๋•Œ
    ์กฐ์ž‘๋œ id๊ฐ€ ์งง๊ฑฐ๋‚˜ ์ž˜๋ชป๋œ ํƒ€์ž…์ผ ๊ฒฝ์šฐ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋‚˜๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
    Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer
    
    ์•„๋งˆ ๋ชฝ๊ณ ๋””๋น„์˜ ObjectId์—์„œ ๋งŒ๋“ค์–ด๋‚ด๋Š” ์—๋Ÿฌ์ธ ๊ฒƒ ๊ฐ™์•„์„œ try - catch ๋ฌธ์œผ๋กœ ์ž„์‹œ ํ•ด๊ฒฐํ•ด ๋ดค์Šต๋‹ˆ๋‹ค.
    ์ด ๋ฐฉ๋ฒ•์ด ์ ์ ˆํ•œ ๊ฑด๊ฐ€์š”?
    
    
    import { connectDB } from "@/util/db";
    import { ObjectId } from "mongodb";
    import Comment from "@/components/Comment";
    import { getServerSession } from "next-auth";
    import { authOptions } from "@/pages/api/auth/[...nextauth]";
    import GaeChuButton from "@/components/GaeChuButton";
    import style from "./Detail.module.scss";
    import common from "@/app/common.module.scss";
    export default async function Detail({ params }) {
      const session = await getServerSession(authOptions);
      const db = (await connectDB).db("next-inside");
      let article;
      try {
        article = await db
          .collection("article")
          .findOne({ _id: new ObjectId(params.articleId) });
        if (!article) {
          return <div>์กด์žฌํ•˜์ง€ ์•Š๋Š” ๊ฒŒ์‹œ๊ธ€์ž…๋‹ˆ๋‹ค.</div>;
        }
      } catch {
        return <div>์กด์žฌํ•˜์ง€ ์•Š๋Š” ๊ฒŒ์‹œ๊ธ€์ž…๋‹ˆ๋‹ค.</div>;
      }
      return (
        <div className={style.Detail}>
          <div
            className={`${style.GallView} ${common.CutCard} ${common["CutCard--Bottom"]}`}
          >
            <div className={style.StickyWrap}>
              <header className={style.GallViewHead}>
                <h2 className={style.GallViewTitle}>{article.title}</h2>
                <p className={style.GallViewAuthor}>{article.author}</p>
              </header>
              <p className={style.GallViewContent}>{article.content}</p>
            </div>
            <GaeChuButton parent={params.articleId} session={session} />
          </div>
          <Comment parent={params.articleId} />
        </div>
      );
    }
     
    #93555

    codingapple
    ํ‚ค ๋งˆ์Šคํ„ฐ
    params.articleId ์— ์ด์ƒํ•œ ๊ณต๋ฐฑ๊ฐ™์€๊ฑด ์—†๋‚˜ _id ํ˜•์‹์€ ๋งž๋‚˜ ์ถœ๋ ฅํ•ด๋ด…์‹œ๋‹ค
2 ๊ธ€ ๋ณด์ž„ - 1 ์—์„œ 2 ๊นŒ์ง€ (์ด 2 ์ค‘์—์„œ)
  • ๋‹ต๋ณ€์€ ๋กœ๊ทธ์ธ ํ›„ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

About

ํ˜„์žฌ ์›” 700๋ช… ์‹ ๊ทœ์ˆ˜๊ฐ•์ค‘์ž…๋‹ˆ๋‹ค.

  (09:00~20:00) ๋น ๋ฅธ ์ƒ๋‹ด์€ ์นดํ†ก ํ”Œ๋Ÿฌ์Šค์นœ๊ตฌ ์ฝ”๋”ฉ์• ํ”Œ (๋งํฌ)
  admin@codingapple.com
  ์ด์šฉ์•ฝ๊ด€, ๊ฐœ์ธ์ •๋ณด์ฒ˜๋ฆฌ๋ฐฉ์นจ
โ“’ Codingapple, ๊ฐ•์˜ ์˜ˆ์ œ, ์˜์ƒ ๋ณต์ œ ๊ธˆ์ง€
top

ยฉ Codingapple, All rights reserved. ์Šˆํผ๋กœ์ผ“ ์—๋“€์ผ€์ด์…˜ / ์„œ์šธํŠน๋ณ„์‹œ ๊ฐ•๋™๊ตฌ ๊ณ ๋•๋กœ 19๊ธธ 30 / ์‚ฌ์—…์ž๋“ฑ๋ก๋ฒˆํ˜ธ : 212-26-14752 ์˜จ๋ผ์ธ ๊ต์œกํ•™์›์—… / ํ†ต์‹ ํŒ๋งค์—…์‹ ๊ณ ๋ฒˆํ˜ธ : ์ œ 2017-์„œ์šธ๊ฐ•๋™-0002 ํ˜ธ / ๊ฐœ์ธ์ •๋ณด๊ด€๋ฆฌ์ž : ๋ฐ•์ข…ํ