Last active
October 12, 2017 04:22
-
-
Save wasabigeek/490532ca6e5e796455fd3844018eb5d5 to your computer and use it in GitHub Desktop.
An Incremental Approach to React with Django: React-Router - After Refactor
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
<!-- /templates/app/app.html --> | |
<!-- replaces /templates/app/a.html and templates/app/b.html --> | |
<div id="reactComponent"></div> |
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
/** | |
/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') | |
) |
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
# /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