next.js

How to add a favicon to a Next.js static site?

妖精的绣舞 提交于 2020-04-10 07:08:43
问题 I'm trying to add a favicon to a Next.js static site without much luck. I've tried customising the document with components from 'next/document' https://nextjs.org/docs/#custom-document A straight link to the favicon.ico file doesn't work because the file isn't included in the build and the href doesn't update to /_next/static/... Importing the image and adding to the link's href doesn't work either (see commented out lines). import React from 'react'; import Document, { Html, Head, Main,

NextJS deploy to a specific URL path

情到浓时终转凉″ 提交于 2020-03-25 18:54:19
问题 I am working on my first NextJS application. When I run "npm run dev" or "npm run start" it deploys my application to http://host:port/ When I navigate to a page the url becomes http://host:port/page1 I need to have my own specific URL, such as http://host:port/my-test-application/path-for-my-app/ http://host:port/my-test-application/path-for-my-app/page1 Furthermore, my app has a lot of elements to link to other areas of the applications, i need these to also go to URL with the basePath and

快速迁移Next.js应用到函数计算

浪尽此生 提交于 2020-03-25 15:38:29
3 月,跳不动了?>>> 首先介绍下在本文出现的几个比较重要的概念: 函数计算(Function Compute): 函数计算是一个事件驱动的服务,通过函数计算,用户无需管理服务器等运行情况,只需编写代码并上传。函数计算准备计算资源,并以弹性伸缩的方式运行用户代码,而用户只需根据实际代码运行所消耗的资源进行付费。函数计算更多信息 参考 。 Fun: Fun 是一个用于支持 Serverless 应用部署的工具,能帮助您便捷地管理函数计算、API 网关、日志服务等资源。它通过一个资源配置文件(template.yml),协助您进行开发、构建、部署操作。Fun 的更多文档 参考 。 备注: 本文介绍的技巧需要 Fun 版本大于等于 3.7.0。 背景 Next.js 是一种 React 的服务端渲染框架,且 Next.js 集成度极高,框架自身集成了 webpack、babel、express 等,使得开发者可以仅依赖 Next、react、react-dom 就可以非常方便的构建自己的 SSR React 应用,开发者甚至都不用像以前那样关心路由。 Next.js 的高度集成性,使得我们很容易就能实现代码分割、路由跳转、热更新以及服务端渲染和前端渲染。 环境准备 首先按照 Fun 的 安装文档 里介绍的方法将 Fun 安装到本机。 PS: 本文介绍的方法,不需要安装 Docker

NextJS with Express : copying files to server and running “npm run start” fails

核能气质少年 提交于 2020-03-25 13:00:27
问题 I am creating a NextJS application and I want to copy ONLY the production files to my server and deploy the application. This works perfectly fine when I do NOT use Express, however when i do use Express the app no longer runs on the server as it says it can not find the "pages" directory. Project structure |- .next |- client |- polyfills.js |- components |- CompA.js |- CompB.js |- etc |- node-modules |- ... |- pages |- index.js |- page1.js |- page2.js |- etc |- public |- appIcon.png |-

NextJS: getInitialProps method

别等时光非礼了梦想. 提交于 2020-03-22 09:45:12
问题 Working with NextJS and saw an example of a page: class IndexPage extends Component { static async getInitialProps(context) { return {}; } render() { return <div>hello world</div>; } } export default withRouter(IndexPage); What exactly does the getInitialProps method in NextJS? 回答1: getInitialProps is usually an async function which is good for asynchronous operations at the server and then it passes data to the page as props. It can run both on the server and on the browser(if you use Link

Import css files from node modules in Next JS?

一世执手 提交于 2020-03-21 16:10:43
问题 I am very new to next.js . Using it for the server side rendering of my application. According to the documentation you can import css files from a static folder which should be in root directory but i want to import css from node_modules because i have extended bootstrap and created my own package. 回答1: This is the solution you are probably looking for: 3 simple steps: Install next-css plugin: npm install --save @zeit/next-css Create in your root directory next.config.js with the following

Import css files from node modules in Next JS?

早过忘川 提交于 2020-03-21 16:10:08
问题 I am very new to next.js . Using it for the server side rendering of my application. According to the documentation you can import css files from a static folder which should be in root directory but i want to import css from node_modules because i have extended bootstrap and created my own package. 回答1: This is the solution you are probably looking for: 3 simple steps: Install next-css plugin: npm install --save @zeit/next-css Create in your root directory next.config.js with the following

程序员必备编程之 Nuxt.js(一)入门详解

◇◆丶佛笑我妖孽 提交于 2020-03-19 12:34:57
3 月,跳不动了?>>> 一.关于Nuxt.js 2016 年 10 月 25 日, zeit.co 背后的团队对外发布了 Next.js ,一个 React 的服务端渲染应用框架。几小时后,与 Next.js 异曲同工,一个基于 Vue.js 的服务端渲染应用框架应运而生,我们称之为: Nuxt.js 。 二. 什么是Nuxt.js Nuxt.js 是一个基于 Vue.js 的轻量级应用框架,可用来创建服务端渲染 (SSR) 应用,也可充当静态站点引擎生成。具有优雅的代码结构分层和热加载等特性。 官方学习指南: https://zh.nuxtjs.org/guide/installation 三.Nuxt的安装使用详解 步骤一: 创建nuxt.js项目 npm 提供的用于更加快捷维护项目的工具 npx 确保安装了npx(npx在NPM版本5.2.0默认安装了) npx create-nuxt-app <项目名> npx create-nuxt-app <project-name> 步骤二: 确定项目名,回车默认即可 步骤三:项目描述,直接回车 步骤四: 作者,回车默认 步骤五:项目语言,确定包管理工具 步骤六: 选择UI框架 步骤七 选择前端服务器框架 步骤八: 选择模块(空格选择) 步骤九: 选择格式化工具(直接回车) 步骤十: 选择测试框架(直接回车) 步骤十一:

this.props.onSave is not a function- Uncaught typescript error

最后都变了- 提交于 2020-03-15 05:49:06
问题 I have a form and when someone saves it I want it to display it in a blog format on my first page. I am getting an error when I click on the "Save" button. The error is: Unhandled Rejection (TypeError): _this.props.onSave is not a function On the line below: handleSave = (e) => e.preventDefault(); const id = this.prop .onSave(this.state.post); How can I resolve this error? I am using Nextjs with Typescript. Here are both my files App.tsx(Routing ) and NewQuestion.tsx(Save button) export

this.props.onSave is not a function- Uncaught typescript error

柔情痞子 提交于 2020-03-15 05:46:12
问题 I have a form and when someone saves it I want it to display it in a blog format on my first page. I am getting an error when I click on the "Save" button. The error is: Unhandled Rejection (TypeError): _this.props.onSave is not a function On the line below: handleSave = (e) => e.preventDefault(); const id = this.prop .onSave(this.state.post); How can I resolve this error? I am using Nextjs with Typescript. Here are both my files App.tsx(Routing ) and NewQuestion.tsx(Save button) export