[React] Create & Deploy a Universal React App using Zeit Next
In this lesson, we'll use next to create a universal React application with no configuration. We'll create page components that will render on the server if accessed directly, but function as you would expect in the client. We'll use the routing capabilities included with next to create links between the components using pushState and we'll incorporate our own React component. Finally, we'll deploy the application to now with a simple command in the terminal.
Setup:
npm init -y
Install:
npm i --save-dev next
Scripts:
"scripts": {
"dev": "next",
"start": "next start",
"build": "next build"
},
Create pages/index.js file:
import React from 'react'; export default () => (
<div>
<h1>Hello next!!</h1>
</div>
)
Run:
npm run dev
Then you can see the index.js page on the localhost:3000.
Add another page:
import React from 'react';
export default class About extends React.Component {
static getInitialProps({req}) {
const name = req ? 'server': 'client';
return {
name: name
};
}
render() {
return (
<div>
<h1>ABOUT PAGE</h1>
<span>
This page is rendering from {this.props.name}
</span>
</div>
);
}
}
This can show whether the page is rendered from the server side or clinet side.
Create a nav component to do the rounting:
// compoennts/nav.js import React from 'react';
import Link from 'next/link'; export default () => (
<div>
<Link href="/">Home</Link>
{' '}
<Link href="/about">About</Link>
</div>
)
Then import to home page and about page.
// index.js import React from 'react';
import Link from 'next/link'; import Nav from '../components/nav'; export default () => (
<div>
<h1>Hello next!!</h1>
<Nav></Nav>
</div>
)
Then we can create an .npmignore to ignore the .next folder in the root.
Last using 'now' to deploy the page to now.
[React] Create & Deploy a Universal React App using Zeit Next的更多相关文章
- [React] Create component variations in React with styled-components and "extend"
In this lesson, we extend the styles of a base button component to create multiple variations of but ...
- 使用React Native来撰写跨平台的App
React Native 是一个 JavaScript 的框架,用来撰写实时的.可原生呈现 iOS 和 Android 的应用.其是基于 React的,而 React 是 Facebook 的用于构建 ...
- [React] Create a Persistent Reference to a Value Using React useRef Hook
The useRef is a hook for creating values that persist across renders. In this lesson we'll learn how ...
- 当今流行的 React.js 适用于怎样的 Web App?
外村 和仁(株式会社 ピクセルグリッド) React.js是什么? React.js是Facebook开发的框架. http://facebook.github.io/react/ 官网上的描述是「 ...
- 2、手把手教React Native实战之从React到RN
###React简介 RN是基于React设计,了解React有助于我们开发RN应用: React希望将功能分解化,让开发变得像搭积木一样,快速而且可维护 React主要有如下3个特点: *作为UI( ...
- React Tutorial: Basic Concept Of React Component---babel, a translator
Getting started with react.js: basic concept of React component 1 What is React.js React, or React.j ...
- 使用react搭建组件库:react+typescript+storybook
前期准备 1. 初始化项目 npx create-react-app react-components --template typescript 2. 安装依赖 使用哪种打包方案:webpack/r ...
- React Canvas:高性能渲染 React 组
React Canvas 提供了使用 Canvas 渲染移动 Web App 界面的能力,替代传统的 DOM 渲染,具有更接近 Native App 的使用体验.React Canvas 提供了一组标 ...
- react实战项目开发(2) react几个重要概念以及JSX语法
前言 前面我们已经学习了利用官方脚手架搭建一套可以应用在生产环境下的React开发环境.那么今天这篇文章主要先了解几个react重要的概念,以及讲解本文的重要知识JSX语法 React重要概念 [思想 ...
随机推荐
- [Javascript] Classify JSON text data with machine learning in Natural
In this lesson, we will learn how to train a Naive Bayes classifier and a Logistic Regression classi ...
- 3. CONFIGURATION官网剖析(博主推荐)
不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ 3. CONFIGURATION 3.1 Broker Configs 3.2 Pr ...
- 洛谷——P1823 音乐会的等待
https://www.luogu.org/problem/show?pid=1823 题目描述 N个人正在排队进入一个音乐会.人们等得很无聊,于是他们开始转来转去,想在队伍里寻找自己的熟人.队列中任 ...
- setting.system-全局属性的设定
SystemProperties跟Settings.System 1 使用 SystemProperties.get如果属性名称以“ro.”开头,那么这个属性被视为只读属性.一旦设置,属性值不能改变. ...
- sass工具、相关插件
http://koala-app.com/index-zh.html 下载koala 把css文件夹(包含.scss后缀的文件)整个拖进去: 然后在sublime打开.scss文件编译,自动生成css ...
- Iptables-主机防火墙设置
基于Iptables构建主机防火墙 Iptables优点: 数据包过滤机制,它会对数据包包头数据进行分析. 1.1.1 加载相关薄块到内核 [root@centos7 ~]# lsmod | egre ...
- 1.1 Introduction中 Distribution官网剖析(博主推荐)
不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Distribution 分布式(Distribution) The partiti ...
- Flume Source官网剖析(博主推荐)
不多说,直接上干货! 一切来源于flume官网 http://flume.apache.org/FlumeUserGuide.html Flume Sources Avro Source Thrift ...
- Mysql5.7.19压缩版安装步骤及踩过的坑
安装Mysql5.7.19压缩版 一:下载压缩包 1.从MySQL官网下载MySQL Community Server 5.7.19,此版本为免费版. 2.下载完成之后解压缩,打开之后文件夹如下: ...
- 00099_commons-IO
1.导入classpath (1)加入classpath的第三方jar包内的class文件才能在项目中使用: (2)创建lib文件夹: (3)将commons-io.jar拷贝到lib文件夹: (4) ...