[关闭]
@c-Ku 2017-11-15T05:22:59.000000Z 字数 1200 阅读 548

React Router筆記(03/07/2017)

NodeJS JavaScript ReactJS


一如既往先安裝腳手架

确保自己安装了nodejs,然后全局安装yeoman
sudo cnpm install -g yo

npm install -g generator-reactpackage

如果node版本比較新,請確認node-sass組建更新到最新版本。

然后初始化應用

yo reactpackage

npm run dev //项目开发过程使用,启动服务,实时刷新
npm run build //开发完成之后打包文件(js、css分开打包)
最後訪問8888端口即可(http://localhost:8888/

  1. 'use strict';
  2. import React from 'react';
  3. import ReactDom from 'react-dom';
  4. import { Router, Route, hashHistory } from 'react-router';
  5. /* 各Router的結構 */
  6. var App = React.createClass({
  7. render: function() {
  8. return (
  9. <div>
  10. <h5 className="title">hello, yeoman app!</h5>
  11. <div>React Router: </div>
  12. <div><a href="#/list">list page</a></div>
  13. <div><a href="#/detail">detail page</a></div>
  14. </div>
  15. );
  16. }
  17. });
  18. var List = React.createClass({
  19. render: function() {
  20. return (
  21. <div>
  22. <h5 className="title">hello, yeoman app!</h5>
  23. <div><a href="#/">返回首页</a></div>
  24. <div>这是列表页</div>
  25. </div>
  26. );
  27. }
  28. });
  29. var Detail = React.createClass({
  30. render: function() {
  31. return (
  32. <div>
  33. <h5 className="title">hello, yeoman app!</h5>
  34. <div><a href="#/">返回首页</a></div>
  35. <div>这是详情页</div>
  36. </div>
  37. );
  38. }
  39. });
  40. //最终渲染
  41. ReactDom.render((
  42. <Router history={hashHistory}>
  43. <Route path='/' component={App}></Route>
  44. <Route path='/list' component={List} />
  45. <Route path='/detail' component={Detail} />
  46. <Route path='/hehe' component={Hehe} />
  47. </Router>
  48. ), document.getElementById('app'));
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注