JiangJun1994 / isomorphic-react-with-mobx

React + MobX + React-Router + Express

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

isomorphic-react-with-mobx

React + MobX + React-Router (CSR & SSR)

How to use

git clone git@github.com:L-x-C/isomorphic-react-with-mobx.git
cd isomorphic-react-with-mobx
npm install

Dev (client-side rendering)

npm start
open http://localhost:3000

Production (server-side rendering)

npm run server
open http://localhost:20000

Preview

Login, Register

Login

Add item to list

List

404 page when routes not match

404

F.A.Q

How to fetch data on the server side?

Adding a onEnter function to a component

@action
static onEnter({states, pathname, query, params}) {
    progressStart();
    return Promise.all([
      menuActions.setTDK(states, '列表'),
      jobActions.fetchJobList(states, query)
    ]);
}

How to redirect on the server side?

In src/helpers/location.js, there is a redirect function, you can just import it and use. The catchErr in src/serverRender.js will catch the redirect command and redirect as you wish. It works on both server and client side.

import {redirect} from './helpers/location';

@action
static onEnter({states, query, params}) {
    redirect('http://www.xxx.com');
}

About

React + MobX + React-Router + Express


Languages

Language:JavaScript 96.9%Language:CSS 3.0%Language:HTML 0.1%Language:Shell 0.0%