next.js

Dynamic routes nextjs with status code 404

帅比萌擦擦* 提交于 2021-02-18 18:56:35
问题 I have a project with dynamic route like /[category]/[product] . After a client-side request via useRouter to graphql for example /hatchback/nissan/ returns a product with a code of 200, but if I make a request to /hatchback/nissan111/ , I get an error because no such route exists and its response code still of 200 instead of 404. How can I check if a route exists and return a 404 status code during the component mount stage? I use SSR to achive this 来源: https://stackoverflow.com/questions

Why NextJS using Docker container did not reload after changed code for dev environment?

混江龙づ霸主 提交于 2021-02-18 14:13:57
问题 I'm trying to run the NextJS on a Docker container using Dockerfile and running via docker-compose, after I changed my code in a JS file (such as index.js) the Next server did not reload. But when I've tried to run outside without using Docker (by executing the "npm run dev" command directly) the Next server did reload smoothly. I've also tried to run the server by "nodemon" command (inside a container), it did not make it either. Dockerfile: FROM node:10.14.2-alpine COPY . /home/next_app

Why NextJS using Docker container did not reload after changed code for dev environment?

你说的曾经没有我的故事 提交于 2021-02-18 14:13:27
问题 I'm trying to run the NextJS on a Docker container using Dockerfile and running via docker-compose, after I changed my code in a JS file (such as index.js) the Next server did not reload. But when I've tried to run outside without using Docker (by executing the "npm run dev" command directly) the Next server did reload smoothly. I've also tried to run the server by "nodemon" command (inside a container), it did not make it either. Dockerfile: FROM node:10.14.2-alpine COPY . /home/next_app

How to paginate data in Firebase in Next.js SSR app?

走远了吗. 提交于 2021-02-16 21:48:48
问题 I am trying to build a next.js server-side rendered blog. For it, I need to paginate the posts data. However, I am yet to find a way to use the query cursors firebase provides to paginate the data. The building query code is: let postsQuery = firebase.firestore().collection('/posts').orderBy('postedOn', 'asc').limitToLast(10); if (currentTagFilter !== 'All') { postsQuery = postsQuery.where('tag', '==', currentTagFilter); } Now, this works for the first page, but I do not know how to request

Get selected item and its count

岁酱吖の 提交于 2021-02-16 15:13:12
问题 I am trying to make a shopping cart app like this site but using reactjs . index.js : (Sending each product to product component ) {products.length > 0 ? products.map((product) => ( <Product key={product.id} product={product} /> )) : ""} components/product.js : <div> {product?.price} <h3> {product.name ? product.name : ""} </h3> <div dangerouslySetInnerHTML={{ __html: product?.description }} /> </div> Also I have the ADD button UI switch code and that will look like, Before clicking add

window is undefined in next js when using materialize css

元气小坏坏 提交于 2021-02-11 17:18:06
问题 I'm using next js. When I try to import M from 'materialize-css'; I get window is undefined . 回答1: You can only import the materialize-css on client side by using dynamic. import dynamic from 'next/dynamic'; const M = dynamic(() => import('materialize-css'), { ssr: false, }); 回答2: I added a useEffect and added this line: if(typeof window !== 'undefined'){ const M = require('materialize-css'); ... } instead of the import statement 来源: https://stackoverflow.com/questions/63292172/window-is

window is undefined in next js when using materialize css

混江龙づ霸主 提交于 2021-02-11 17:16:51
问题 I'm using next js. When I try to import M from 'materialize-css'; I get window is undefined . 回答1: You can only import the materialize-css on client side by using dynamic. import dynamic from 'next/dynamic'; const M = dynamic(() => import('materialize-css'), { ssr: false, }); 回答2: I added a useEffect and added this line: if(typeof window !== 'undefined'){ const M = require('materialize-css'); ... } instead of the import statement 来源: https://stackoverflow.com/questions/63292172/window-is

window is undefined in next js when using materialize css

戏子无情 提交于 2021-02-11 17:16:29
问题 I'm using next js. When I try to import M from 'materialize-css'; I get window is undefined . 回答1: You can only import the materialize-css on client side by using dynamic. import dynamic from 'next/dynamic'; const M = dynamic(() => import('materialize-css'), { ssr: false, }); 回答2: I added a useEffect and added this line: if(typeof window !== 'undefined'){ const M = require('materialize-css'); ... } instead of the import statement 来源: https://stackoverflow.com/questions/63292172/window-is

How to cache NextJS 10.0 images using NGINX

时光总嘲笑我的痴心妄想 提交于 2021-02-11 14:17:58
问题 We would like to launch a NextJS 10 app using NGINX so we use a configuration similar to: location /_next/static/ { alias /home/ec2-user/my-app/.next/static/; expires 1y; access_log on; } It works great, it caches for a year our statics but as we use NextJS images I'm failing to add an expires tag on on-the-fly resized images. If I do: location /_next/image/ { alias /home/ec2-user/my-app/.next/image; expires 1y; access_log on; } It just returns a 404 on images. Here is my server part NGINX

NextJs: 404 page back button returns back to 404 page

微笑、不失礼 提交于 2021-02-11 14:16:11
问题 I have a condition inside my lifecycle method of user Page such that if the user enters an URL with certain parameters such as somePage.com/user/1 will fetch the data of the user with ID 1, however, if the user enters the URL as somePage.com/user/1ABC then im routing them to a custom 404 page. My issue is when im in the 404-page clicking on the back button will take me back to the page with URL somePage.com/user/1ABC and then will route back to the same 404-page as the URL param met a