Skip to content

L-x-C/isomorphic-react-with-mobx

Repository files navigation

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');
}

Releases

No releases published

Packages

No packages published

Languages