-
Notifications
You must be signed in to change notification settings - Fork 16
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
[Discussion] Effectively using react-router with a django project #11
Comments
I was using a mix of the two. At the end of the django's url.py i had: # Catch-All: These urls are handled by the single page BaseApp and react-router
urlpatterns += [
url(r'^.*/', TemplateView.as_view(template_name="base-react.html"), name='base')
] 404 then have to be handled by React |
Thanks @awhillas, I would recommend this approach too |
Might be handy to have a default Django template with the minimum HTML need to get this working. I confess i'm struggling to figure out what it need to do it see the basic counter example...? |
@awhillas did you try to set up with the 'existing project' flag? Also make sure you set the output dir to |
Yeah, i have it working from my project folder but not exactly with my project. I removed the output: {
path: path.resolve(PROJECT_ROOT, "myapp/static/scripts"),
filename: "[name].js",
}, and in my template i have at the bottom: {% if settings.DJANGO_DEV %}{# i.e. we're local #}
<script src="http://localhost:8080/webpack-dev-server.js"></script>
{% endif %}
<script src="{% static "scripts/vendor.js" %}"></script>
<script src="{% static "scripts/main.js" %}"></script>
</body>
</html> which gives weird results when running Perviously, i had webpack with the Some examples would be helpful :) |
With some research I found:
from: https://webpack.github.io/docs/webpack-dev-server.html#combining-with-an-existing-server So i guess my {% if settings.DJANGO_DEV %}
<script src="http://localhost:8080/webpack-dev-server.js"></script>
<script src="http://localhost:8080/build/vendor.js"></script>
<script src="http://localhost:8080/build/main.js"></script>
{% endif %} if i have this in my webpack config: context: PROJECT_ROOT,
output: {
path: path.resolve(PROJECT_ROOT, "scout/static/scripts"),
filename: "[name].js",
publicPath: "/build/",
}, All good now! |
I should add some docs for this but the best way to do this IMHO is to use the generated webpack stats json file. There is a django plugin that works very well with this: https://github.com/owais/django-webpack-loader |
@awhillas if you generate a cookiecutter-webpack project and you use the |
Just googled this independently and found django-webpack-loader myself and was on my way back here to note it :D |
@awhillas you save my life!))) |
@HoangJerry you're probably sending invalid data to highcharts. Recheck your data structure and data type. |
@awhillas I'm curious how you handle state and preserving the app state when refreshing the page when the user has navigated to a subcomponent / nested route. |
Are there any models for effectively using react router in a django project?
There are two routers in a cookiecutter-django/cookiecutter-webpack project currently, the django urls and react-router. Should these both exist together or should one be removed?
The two together currently don't exist well as explained here cookiecutter/cookiecutter-django#637
The redirect in the
routes.js
could be removed to allow django urls to work but I think the webpack install should be moved to home template and shouldn't exist on the base template. (This allows both routes to work).The text was updated successfully, but these errors were encountered: