Building A Blog By React Ecosystem(2)

Add React-Router to our project

Code style is important

npm install -g eslint

And then enter the root directory

type eslint init

There are some styles but I recommend Airbnb 's style. I believe this time there are many companies use it to develop.

Also, we can write a file to specify which style we need and where effects. touch a .eslintrc.jseg:

module.exports = {
  extends: 'airbnb',
  installedESLint: true,
  plugins: [
    'react',
  ],
  env: {
    browser: true,
    node: true,
  },
};

It means that we need style in client and node .
Furthermore, I recommend using VSCode to develop our projects because of its future that can auto-complete the out-style code , that is why I use VSCode instead of Atom.

After that, touch routes.js file in the client directory .

import React from 'react';
import { Router, Route } from 'react-router';

import App from './containers/App';

export default function (history) {
  return (
    <Router history={history}>
      <Route path="/" components={App} />
    </Router>
  );
}

From those codes, you must find that the App components' position changes from components to containers. Because we also need Redux to build our project, and the author of Redux , Dan Abramov, also recommend an architecture of managing components, which classified React component to two type : " dumb component " and " smart component " . So the components in containers can receive props and communicate with outside components but the components in components can't , the purpose to simplify the store ' state .

Then edit index.js file in client.

render((
createRoutes(browserHistory)
),
document.getElementById('app'));

To here React-Router is a part of our project.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,813评论 0 23
  • 1 我睁开眼睛,一片刺眼的亮光立刻照了进来,我下意识想用手去遮,却发现手指被一个小东西牵扯着。 这是什么?待眼睛逐...
    蔻蔻小鱼阅读 687评论 6 5
  • 昨天晚上和小何约好的一起起早赶地铁,哪想到我们俩相互指望对方定闹钟,结果都没定闹钟,起床时已经7点半,外面下着雨,...
    二石兄阅读 250评论 0 0
  • 高血糖在早期可以毫无症状也无异常,常常因为体检才发现,但到了晚期可以形成严重疾病,甚至危及生命。 血糖是否平衡是测...
    伊能启元阅读 295评论 0 0
  • 等不到的人就别等了吧,爱不到的人就别爱了吧,以免蹉跎了岁月,辜负了自己。 关于爱情,一直都是人类永恒的话题。但不同...
    夏沫星空阅读 188评论 0 2