-
Notifications
You must be signed in to change notification settings - Fork 498
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
Getting react router working with Django #559
Comments
Got this working. One of the components in my frontend was erroring out, and the entire frontend wasn't getting rendered. |
For ones who are new (just like me), to add about page you need to: backend/common/urls.py urlpatterns = [
- path("", views.IndexView.as_view(), name="index"),
+ re_path("", views.IndexView.as_view(), name="index"),
+ re_path("/about", views.IndexView.as_view(), name="index"),
] frontend/js/App.js const App = () => (
<Sentry.ErrorBoundary fallback={<p>An error has occurred</p>}>
<Provider store={store}>
- <Home />
+ <BrowserRouter>
+ <Routes>
+ <Route path="/" index element={<Home />} />
+ <Route path="/about" index element={<About />} />
+ </Routes>
+ </BrowserRouter>
</Provider>
</Sentry.ErrorBoundary>
); However, I'm still very confused about why do routes need to be managed & declared at both BE & FE side. That looks redundant & not DRY to me. |
@terrynguyen255 to avoiding repeating routes in backend/frontend, you need to catch all possible frontend routes in a single URL conf in Django, and direct all of them to IndexView or similar. An easy way to do this is to put a catch-all URL pattern as your final one, like this: https://stackoverflow.com/a/71836642 I will re-open this issue to document this better in the README for other users. But you don't need anything specific from this boilerplate to solve this issue. Let me know if you still have questions. |
Describe the bug
The boilerplate code works for me. After integrating my backend, am able to query it through Postman and get expected responses. From frontend, I could see the div with "react-app" id replaced with my frontend, for the landing page.
However, my frontend uses "react-router-dom", and need to serve many paths/urls. If I just try to navigate to another path in my frontend, I get a 404 with the following error (with DEBUG=True in Django):
Could you please help how to serve multiple paths from frontend with this boilerplate code. Thanks!
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Be able to serve multiple paths from the frontend.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: