-
Notifications
You must be signed in to change notification settings - Fork 27
Add new page
peterchang edited this page May 20, 2017
·
9 revisions
It is aa example of adding a static new page(no action) base on the boilerplate, there are 3 files which will be modified(or added).
import React, { PropTypes } from 'react'
const NewPage = ({ onClick, message }) => {
return (
<div>
<h1>NewPage: { message }</h1>
</div>
)
}
NewPage.propTypes = {
message: PropTypes.string.isRequired
}
export default NewPage
import { connect } from 'react-redux'
import NewPage from '../components/NewPage'
const mapStateToProps = (state, ownProps) => {
return {
message: 'well behave !!!'
}
}
const mapDispatchToProps = (dispatch, ownProps) => {
return {
}
}
const newPage = connect(
mapStateToProps,
mapDispatchToProps
)(NewPage)
// initState is a function which is run before server, and keep consistency as a thunk middleware, and return a promise
newPage.initState = (store,req,res) => {
return (dispatch, getState) => {
return new Promise( (resolve, reject)=> {
resolve ()
})
}
}
export default newPage
The new page is created with new URL /preload', as the first field
path: '/preload'`
...
{
path: '/preload',
component: PreloadHelloWorld,
initState: PreloadHelloWorld.initState
},
...
Open browser with url localhost:3000/newpage
![screen shot 2017-05-19 at 11 10 08 pm](https://cloud.githubusercontent.com/assets/5538753/26254219/578fe700-3ce8-11e7-8aa3-44542b649264.png)
To get the finished repos
$ git clone https://github.com/wahengchang/react-redux-boilerplate/tree/addNewPage
https://github.com/wahengchang/react-redux-boilerplate/tree/addNewPage