Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are there any plans to support hot-loaded routes? #12

Open
zspecza opened this issue Jul 6, 2015 · 1 comment
Open

Are there any plans to support hot-loaded routes? #12

zspecza opened this issue Jul 6, 2015 · 1 comment

Comments

@zspecza
Copy link

zspecza commented Jul 6, 2015

It's a given that using react-hot-loader, you can hot-reload components, but I go one extra step further and hot load route file changes as well with this setup:

/*
  main entry file
 */

// import dependencies
import React     from 'react/addons'
import Router    from 'react-router'
import routes    from './routes'

import fetchData from './utils/fetchData'
import getTitle  from './utils/getTitle'

// create client-side router
const router = Router.create({ routes, location: Router.HistoryLocation })

// if this is a hot module update, replace the routes with new state
if (module.hot) {
  module.hot.accept(
    './routes', () => router.replaceRoutes(require('./routes'))
  )
}

// run the app
router.run((Handler, state) => {
  fetchData(state.routes, state.params, (err, props) => {
    React.render(<Handler {...props} />, document)
    document.title = getTitle(state.routes, state.params, props)
  })
})

This is made possible by enabling the manual option on react-hot-loader in the Webpack config like so:

loaders: [{
  test: /\.jsx?$/,
  loaders: ['react-hot?manual', 'babel?optional[]=runtime&stage=0'],
  exclude: [nodeModulesPath]
}]

I'm often making changes to the routes.js file and would love to use this project to reduce that fetchData boilerplate code, and not supporting this kind of setup is the only thing keeping me from using this module (really great work, by the way!)

@romainberger
Copy link
Contributor

Hi,
We're currently looking into react-hot-loader, I'll try your example and let you know if we find something interesting.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants