Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Last active September 13, 2016 21:54
Show Gist options
  • Save ryanflorence/5c14a9fd1a8a24de503b578b24f54f60 to your computer and use it in GitHub Desktop.
Save ryanflorence/5c14a9fd1a8a24de503b578b24f54f60 to your computer and use it in GitHub Desktop.
import { matchPattern } from 'react-router'
const routes = [
{
pattern: '/one',
fetch: () => {
return Promise.resolve('one')
}
},
{
pattern: '/two',
fetch: () => {
return Promise.resolve('two')
}
},
{
pattern: '/three',
fetch: () => {
return Promise.resolve('three')
}
},
]
const fetchDataForRoute = (path) => {
Promise.all(
routes.filter(route => (
matchPattern(route.pattern, { pathname: path }))
).map(route => route.fetch())
)
}
fetchDataForRoute('/one').then((data) => {
// cache the data
// render
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment