Last active
November 1, 2018 14:59
-
-
Save xudaolong/6b3c36c38a617ff2854460ac83efab32 to your computer and use it in GitHub Desktop.
react-router|-|&tag=react
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component, PropTypes } from 'react'; | |
import Loading from 'components/Loading'; | |
export default class List extends Component { | |
static propTypes = { | |
data: PropTypes.array.isRequired, | |
fetch: PropTypes.func.isRequired, | |
isFetching: PropTypes.bool.isRequired, | |
}; | |
componentDidMount() { | |
this.props.fetch(); | |
} | |
render() { | |
const { isFetching, data } = this.props; | |
return ( | |
<ul> | |
{isFetching && <Loading message="Retrieving posts..." />} | |
{data.map(entry => <li key={entry.id}>{entry.title}</li>)} | |
</ul> | |
) | |
} | |
} | |
server { | |
... | |
location / { | |
try_files $uri /index.html; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const path = require('path') | |
const port = process.env.PORT || 8080 | |
const app = express() | |
// serve static assets normally | |
app.use(express.static(__dirname + '/public')) | |
// handle every other route with index.html, which will contain | |
// a script tag to your application's JavaScript file(s). | |
app.get('*', function (request, response){ | |
response.sendFile(path.resolve(__dirname, 'public', 'index.html')) | |
}) | |
app.listen(port) | |
console.log("server started on port " + port) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment