Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How do I use URL routing? #242

Discussion options

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?

You must be logged in to vote

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

  1. 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)
  2. 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

Comment options

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

  1. 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)
  2. Make sure to handle those routes within ReactPy Router.
django_router(
 route("/exmaple/route/123", html.div("Example 1")),
 route("/router/*", html.div("Fallback")),
)
You must be logged in to vote
2 replies
Comment options

I have tried implementing this router and the page does refresh whenever I visit a new link. Can I get a full snippet?

Comment options

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.

Answer selected by Archmonger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /