Giter VIP home page Giter VIP logo

react-ssr's Introduction

React服务端渲染,使用方式:

1、到node_server文件夹下,执行npm install,然后执行node app.js,启动后端接口的服务器(端口为4000,用其他语言实现均可)

2、npm install nodemon npm-run-all -g 全局安装nodemon工具和npm-run-all,不然之后的项目命令会无法识别

3、到my_ssr文件夹下,执行npm install, 然后执行npm run dev启动项目(命令配置细节请看package.json里面的script内容),打开浏览器通过localhost:3001即可访问。

配套技术点详解文章地址: https://juejin.im/post/5d1fe6be51882579db031a6d

react-ssr's People

Contributors

sanyuan0704 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-ssr's Issues

怎么让某一个路由不在server端渲染

有一些功能需要用到外部的一些组件,但这个组件里面是要使用window对象的,服务器渲染的话就会报错,window is undefined. 有没有办法让某一个路由不在server端渲染

part1代码执行报错

根据readme文档配置,可以正常运行。

然后做以下更改:
将containers/Home/index.js替换为part1中的代码:

// containers/Home.js import React from 'react'; const Home = () => { return ( <div> <div>This is sanyuan</div> </div> ) } export default Home

将server/index.js替换为part1中的代码:

`// server/index.js
import express from 'express';
import { renderToString } from 'react-dom/server';
import Home from "../containers/Home"

const app = express();
const content = renderToString();
app.get('/', function (req, res) {
res.send(
<html> <head> <title>ssr</title> </head> <body> <div id="root">${content}</div> </body> </html>
);
})
app.listen(3001, () => {
console.log('listen:3001')
})`

代码报错:ReferenceError: React is not defined

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.