Skip to content

Instantly share code, notes, and snippets.

@wasabigeek
Last active October 12, 2017 04:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wasabigeek/490532ca6e5e796455fd3844018eb5d5 to your computer and use it in GitHub Desktop.
Save wasabigeek/490532ca6e5e796455fd3844018eb5d5 to your computer and use it in GitHub Desktop.
An Incremental Approach to React with Django: React-Router - After Refactor
<!-- /templates/app/app.html -->
<!-- replaces /templates/app/a.html and templates/app/b.html -->
<div id="reactComponent"></div>
/**
/static/js/app.js
we remove /static/js/app/a.js and /static/js/app/b.js, instead rendering the components in a single file
*/
const AppComponent = () => (
<Router basename="/app">
<div>
<Route path="/a" component={PageAComponent}/>
<Route path="/b" component={PageBComponent}/>
</div>
</Router>
)
ReactDOM.render(
<AppComponent/>,
document.getElementById('reactComponent')
)
# /project/urls.py
# we remove /app/urls.py
urlpatterns = [
url(r'^app/', TemplateView.as_view(template_name='app.html')),
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment