不会的要多查多问,不然不会的永远不会,哪怕你离会就差了那么一点点
react 嵌套路由相关
[ 2016/09/21 12:58 | by 刘新修 ]
/src/js/app.js
JavaScript代码
- import React, { PropTypes, Component } from 'react';
- import {render} from 'react-dom'; //render((_component),Dom);
- //import ReactDOM from 'react-dom'; //ReactDOM.render((_component),Dom);
- import getRouter from './getRouter';
- import { Router, Route, Link, IndexRoute, hashHistory } from 'react-router';
- /* using an ES6 transpiler, like babel */
- //import { createHistory } from 'history/createBrowserHistory'
- //import createBrowserHistory from 'history/createBrowserHistory';
- /* Import Component */
- import Hello from '../components/hello/hello.jsx'
- import Other from '../components/other/other.jsx'
- /* ensure test */
- require.ensure(['./test'],function(require){
- var aModule = require('./test');
- console.log("xxxx");
- },'test');
- /* create history for router */
- //const history = createHistory()
- /* Router Config */
- render((
- <Router history={hashHistory}>
- <Route path="/" component={getRouter}>
- <IndexRoute component={Hello} />
- <Route path="other" component={Other} />
- </Route>
- </Router>
- ), document.getElementById('app'));
/src/js/getRouter.js
JavaScript代码
- import React, { PropTypes, Component } from 'react';
- export default React.createClass ({
- render() {
- return <div>
- {this.props.children}
- </div>
- }
- });
/src/components/hello/hello.jsx
JavaScript代码
- import React, { PropTypes, Component } from 'react';
- /* 导入组件样式hello.css */
- import styles from './css/hello.css';
- //require("./css/hello.css");
- class Hello extends React.Component {
- render(){
- return (
- <div className="hello">
- <p>Hello World!!!!!!!...</p>
- <p>cll不错!</p>
- </div>
- );
- };
- };
- export default Hello;
/src/components/other/other.jsx
JavaScript代码
- class Other extends React.Component {
- render() {
- return (
- <div>
- <p>this is other component!!!</p>
- <p>111111111cll不错!</p>
- </div>
- )
- }
- }
- export default Other;