Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Commit edd820f

Browse files
author
TsaiKoga
committed
Finish lesson 8: Add IndexRoute 使组件不在this.props.children中
1 parent d9e16ef commit edd820f

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

lessons/08-index-routes/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import React from 'react'
22
import { render } from 'react-dom'
3-
import { Router, Route, hashHistory } from 'react-router'
3+
// add `IndexRoute` to 'react-router' imports
4+
import { Router, Route, hashHistory, IndexRoute} from 'react-router'
45
import App from './modules/App'
56
import About from './modules/About'
67
import Repos from './modules/Repos'
78
import Repo from './modules/Repo'
9+
// and the Home component
10+
import Home from './modules/Home'
811

912
render((
1013
<Router history={hashHistory}>
1114
<Route path="/" component={App}>
15+
{/* add it here, as a child of `/` */}
16+
<IndexRoute component={Home}/>
17+
1218
<Route path="/repos" component={Repos}>
1319
<Route path="/repos/:userName/:repoName" component={Repo}/>
1420
</Route>

lessons/08-index-routes/modules/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default React.createClass({
1010
<li><NavLink to="/about">About</NavLink></li>
1111
<li><NavLink to="/repos">Repos</NavLink></li>
1212
</ul>
13-
{this.props.children}
13+
{this.props.children || <Home />}
1414
</div>
1515
)
1616
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react'
2+
3+
export default React.createClass({
4+
render() {
5+
return (
6+
<div>Home</div>
7+
)
8+
}
9+
})

0 commit comments

Comments
 (0)