forked from reactive-python/reactpy-django
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponents.py
42 lines (36 loc) · 1.41 KB
/
components.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from reactpy import component, html, use_location
from reactpy_django.router import django_router
from reactpy_router import route, use_params, use_query
@component
def display_params(*args):
params = use_params()
return html._(
html.div(f"Params: {params}"),
*args,
)
@component
def main():
location = use_location()
query = use_query()
route_info = html._(
html.div(
{"id": "router-path", "data-path": location.pathname},
f"Path Name: {location.pathname}",
),
html.div(f"Query String: {location.search}"),
html.div(f"Query: {query}"),
)
return django_router(
route("/router/", html.div("Path 1", route_info)),
route("/router/any/<value>/", display_params("Path 2", route_info)),
route("/router/integer/<int:value>/", display_params("Path 3", route_info)),
route("/router/path/<path:value>/", display_params("Path 4", route_info)),
route("/router/slug/<slug:value>/", display_params("Path 5", route_info)),
route("/router/string/<str:value>/", display_params("Path 6", route_info)),
route("/router/uuid/<uuid:value>/", display_params("Path 7", route_info)),
route("/router/", None, route("abc/", display_params("Path 8", route_info))),
route(
"/router/two/<int:value>/<str:value2>/",
display_params("Path 9", route_info),
),
)