Relative Content

Tag Archive for next.jsnext.js13

How to fetch dynamic data in Next Js from database (eg. mongo DB) using Next Js API routes

I am currently building a small ecommerce shop and I am fetching data from mongo Db database to display to the user, the problem I have is that I am not getting the latest data from the database after I run the build command which seems to statically build each product data with the current data contained in the database and any updates on the data in the database does not reflect to the frontend. Here is my code in details (my code folder structure is in src>app)

How to make the Server component whenever the URL parameters changes

Can someone enlighten me on this? is it possible to trigger a re-fetch of data whenever the url parameter changes? because I tried this and it won’t work, on context I’m using router.navigate instead of link and also doesn’t work. Below is the code for your reference.

it is not possible to transfer a variable to another variable

const [img, setImg] = useState(“”); const handleInputChange = (event) => { console.log(“event”, event.target.files); setData({ …data, loading: true }); img = event.target.files[0]; const info = new FormData(); info.append(“file”, img); axios.post(“http://localhost:3001/uploadImage/”, info, { headers: { “content-type”: “application/x-www-form-urlencoded”, }, }); }; я пытался получить “img” из const, но он выдаёт ошибку, почему? next.js next.js13 New contributor Максим Солдаткин […]

SingletonRouter is Null using NextJS13 imported from “next/router”

Context I’m trying to cancel the routing change when the user leaves the page without saving changes. To achieve this in Next.js, I need to listen to routing changes and cancel them using a handler function as middleware to intercept the route change Like this: import { Router } from ‘next/router’ Router.events.on(‘routeChangeStart’, handleChange) in order […]

Best way to embed Nextjs app in another website

I have a Nextjs app using app-directory and server-side rendering, I have been asked to create a white-label version for third parties to host on their websites, the simplest way is to use Iframe but it does not work properly due to router issues, and redirects do not work. the database is already configured for multiple organizations but I am not sure how to let the app know which organization is requesting the data. the ideal solution I am looking for is to host Nextjs on Vercel or Netlify, embed it somehow in another website, and let the app detect the organization based on the hostname