-
-
Notifications
You must be signed in to change notification settings - Fork 22
How do I use URL routing? #242
-
from reactpy_django.router import django_router from reactpy_router import route Is there a way to use this routing approach to override django urls? I need to have those routing to be done using django_router and route instead of django urls routing. I am wondering how I can do this since the django urls are being used. Any clue?
Beta Was this translation helpful? Give feedback.
All reactions
You need to register the URL endpoints with both Django and ReactPy. Unfortunately there was no way for us to automate this.
For example, if you know that all /example/route/ URLs will need to be handled by ReactPy, then you will need to
- Register the URL with Django, as permissively as needed.
- For example, the following would match all paths starting with
/example/route/ re_path(r"^/example/route/.*$", my_reactpy_view)
- For example, the following would match all paths starting with
- Make sure to handle those routes within ReactPy Router.
django_router( route("/exmaple/route/123", html.div("Example 1")), route("/router/*", html.div("Fallback")), )
Replies: 1 comment 2 replies
-
You need to register the URL endpoints with both Django and ReactPy. Unfortunately there was no way for us to automate this.
For example, if you know that all /example/route/ URLs will need to be handled by ReactPy, then you will need to
- Register the URL with Django, as permissively as needed.
- For example, the following would match all paths starting with
/example/route/ re_path(r"^/example/route/.*$", my_reactpy_view)
- For example, the following would match all paths starting with
- Make sure to handle those routes within ReactPy Router.
django_router( route("/exmaple/route/123", html.div("Example 1")), route("/router/*", html.div("Fallback")), )
Beta Was this translation helpful? Give feedback.
All reactions
-
I have tried implementing this router and the page does refresh whenever I visit a new link. Can I get a full snippet?
Beta Was this translation helpful? Give feedback.
All reactions
-
You need to utilize the reactpy_router.link component instead of using the traditional reactpy.html.a.
As a side note, there is a bug the children of reactpy_router.html.link must be plain reactpy.html and not component types. I am working on resolving that now.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1