From the course: Next.js 14 from Scratch: Build a Real-World Project Using Next.js 14 and MongoDB
Unlock this course with a free trial
Join today to access over 25,200 courses taught by industry experts.
Fetch single property - Next.js Tutorial
From the course: Next.js 14 from Scratch: Build a Real-World Project Using Next.js 14 and MongoDB
Fetch single property
All right, guys. So now we want to fetch a single property from the database. And that's going to be displayed on this page. So the first thing we want to do is create our API route. So let's go to API, our app API. And then in properties, we're going to create a folder called brackets ID, just like we did with the front end page. So in here, we'll create a route.js. So hopefully that makes sense. The convention for front end pages our components is page.jsx. And for API routes, it's going to be route.js. Oh, did I put jsx? I did not mean to do that. Let's rename that to js. Yeah, so that should still work. Honestly, I didn't think that that would even work with jsx, but apparently it does. All right, so in this route.js in the brackets ID, Actually, let's just copy what we have here in this route, paste that in here, because we're still going to need to connect to the database. We're going to need our property model. And then this is going to be slash and then the ID. It's going to…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Create MongoDB database8m 44s
-
(Locked)
MongoDB Compass and importing data4m 36s
-
(Locked)
Database connection and Mongoose6m 31s
-
(Locked)
Your first API route6m 5s
-
(Locked)
Property and user models12m 30s
-
(Locked)
Fetch data using server component9m 48s
-
(Locked)
Requests file4m 25s
-
(Locked)
Fetch single property10m 51s
-
(Locked)
Single property page11m 54s
-
(Locked)
Property details component15m 34s
-
(Locked)
Spinner component2m 37s
-
(Locked)
-
-
-
-
-
-
-