Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
69598ef
Bump workflows
Archmonger Feb 22, 2024
c86f37b
use_query -> use_search_params
Archmonger Jun 25, 2024
ec1b633
use_params docstring
Archmonger Jun 25, 2024
332ca75
better error for route state
Archmonger Jun 25, 2024
189b484
simple.router -> browser_router
Archmonger Jun 25, 2024
6557000
Allow multi-component routes
Archmonger Jun 25, 2024
9e72ca0
Fix potential key identity bug of router component children
Archmonger Jun 25, 2024
7a242e1
Add slug conversion type
Archmonger Jun 25, 2024
e92842f
SimpleResolver -> Resolver, CONVERSION_TYPES -> CONVERTERS, file refa…
Archmonger Jun 25, 2024
f46d9d1
allow customizable match_any_identifier
Archmonger Jun 25, 2024
b8efe54
attempt to fix workflows
Archmonger Jun 25, 2024
bee18a5
server-side link component
Archmonger Jun 25, 2024
de53beb
fix a handful of test errors
Archmonger Jun 26, 2024
f77f052
change js output directory
Archmonger Jun 26, 2024
518d226
fix py3.9 type hints
Archmonger Jun 26, 2024
e96a512
Change star pattern to `{NAME:any}`
Archmonger Jun 28, 2024
03b8f2c
Fix router in local environment
Archmonger Oct 5, 2024
37760bb
Fix link component
Archmonger Oct 5, 2024
ee616d0
Fix route parameters
Archmonger Oct 5, 2024
169e2dc
remove black from workflow
Archmonger Oct 5, 2024
5ffc34f
Format with ruff + prettier
Archmonger Oct 5, 2024
8b057b2
Fix github actions
Archmonger Oct 5, 2024
db9e074
Fix use_search_params
Archmonger Oct 5, 2024
7947e91
Clean up use-params example
Archmonger Oct 5, 2024
d9a943a
Remove select from top level router
Archmonger Oct 5, 2024
94e9de5
docs tweaks
Archmonger Oct 6, 2024
afb97c8
js tweaks
Archmonger Oct 6, 2024
78c7c49
Refactor some more docs
Archmonger Oct 6, 2024
1b8031b
Better mkdocstrings
Archmonger Oct 6, 2024
f52aaa3
Remove core.py
Archmonger Oct 6, 2024
bad417f
cleaner example for use params
Archmonger Oct 6, 2024
155079b
ignore link click type
Archmonger Oct 6, 2024
c7d19f6
Move event loop policy to dedicated fixture
Archmonger Oct 6, 2024
d7184b1
Fix resolver tests
Archmonger Oct 6, 2024
6857f7a
fix type errors
Archmonger Oct 6, 2024
fa0f307
use link class instead of ID
Archmonger Oct 6, 2024
1723f8d
prefix uuid with a string
Archmonger Oct 6, 2024
b67101a
add test for link search params
Archmonger Oct 6, 2024
c38ac3b
Remove coverage from some unneeded places
Archmonger Oct 6, 2024
f57b63b
Fix browser history
Archmonger Oct 6, 2024
88d1f46
use server side prevent default
Archmonger Oct 6, 2024
a78a5b1
Server side handling of relative URLs
Archmonger Oct 6, 2024
97a715c
Add test for class name
Archmonger Oct 7, 2024
4633ab2
fix last coverage hit
Archmonger Oct 7, 2024
70a7ea0
self review
Archmonger Oct 11, 2024
98ac776
Add click delay (attempt to fix flakey tests)
Archmonger Oct 11, 2024
9fc92ce
Add changelog
Archmonger Oct 11, 2024
0e87d27
Increase delay
Archmonger Oct 11, 2024
0469615
Remove unneeded homepage stuff
Archmonger Oct 12, 2024
1d33c65
Use ReactJS event naming conventions
Archmonger Oct 12, 2024
25e440f
Self review: Use JS component as background listener for link clicks
Archmonger Oct 12, 2024
8e9b6a8
use attributes dict for all link parameters
Archmonger Oct 12, 2024
05e7012
Allow reconnections to re-obtain the current URL
Archmonger Oct 12, 2024
afa8c83
Add new changelog item
Archmonger Oct 12, 2024
972c275
Revert to dumb script for links
Archmonger Oct 12, 2024
ff65483
no cov on exception
Archmonger Oct 12, 2024
7e10dd4
fix test
Archmonger Oct 12, 2024
78b5a95
Fix spelling
Archmonger Oct 12, 2024
2d88133
Update src/reactpy_router/resolvers.py
Archmonger Oct 13, 2024
b1192c5
use unpacking instead of list
Archmonger Oct 14, 2024
9d18fc9
safer query string parsing
Archmonger Oct 14, 2024
df4c088
Remove unused import
Archmonger Oct 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use server side prevent default
  • Loading branch information
Archmonger committed Oct 6, 2024
commit 88d1f46a89a0b2d95cb87a4c8d6e1afed0891d40
11 changes: 6 additions & 5 deletions src/reactpy_router/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Any
from uuid import uuid4

from reactpy import component, html
from reactpy import component, event, html
from reactpy.backend.types import Location
from reactpy.core.types import VdomChild, VdomDict
from reactpy.web.module import export, module_from_file
Expand All @@ -26,15 +26,16 @@ def link(*children: VdomChild, to: str, **attributes: Any) -> VdomDict:
# properly sets the location. When a client-server communication layer is added to a \
# future ReactPy release, this component will need to be rewritten to use that instead. \
set_location = _use_route_state().set_location
class_uuid = f"link-{uuid4().hex}"

@event(prevent_default=True)
def on_click(_event: dict[str, Any]) -> None:
pathname, search = to.split("?", 1) if "?" in to else (to, "")
if search:
search = f"?{search}"
set_location(Location(pathname, search))

class_name = class_uuid
uuid_string = f"link-{uuid4().hex}"
class_name = f"{uuid_string}"
if "className" in attributes:
class_name = " ".join([attributes.pop("className"), class_name])
# TODO: This can be removed when ReactPy stops supporting underscores in attribute names
Expand All @@ -45,9 +46,9 @@ def on_click(_event: dict[str, Any]) -> None:
**attributes,
"href": to,
"onClick": on_click,
"className": class_uuid,
"className": class_name,
}
return html._(html.a(attrs, *children), html.script(link_js_content.replace("UUID", class_uuid)))
return html._(html.a(attrs, *children), html.script(link_js_content.replace("UUID", uuid_string)))


def route(path: str, element: Any | None, *routes: Route) -> Route:
Expand Down
1 change: 0 additions & 1 deletion src/reactpy_router/static/link.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
document.querySelector(".UUID").addEventListener(
"click",
(event) => {
event.preventDefault();
let to = event.target.getAttribute("href");
window.history.pushState({}, to, new URL(to, window.location));
},
Expand Down