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
simple.router -> browser_router
  • Loading branch information
Archmonger committed Jun 25, 2024
commit 189b484d24d532c5bb8f4f69c3036e036122b288
5 changes: 2 additions & 3 deletions docs/examples/python/basic-routing-more-routes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from reactpy import component, html, run

from reactpy_router import route, simple
from reactpy_router import browser_router, route


@component
def root():
return simple.router(
return browser_router(
route("/", html.h1("Home Page 🏠")),
route("/messages", html.h1("Messages 💬")),
route("*", html.h1("Missing Link 🔗‍💥")),
Expand Down
5 changes: 2 additions & 3 deletions docs/examples/python/basic-routing.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from reactpy import component, html, run

from reactpy_router import route, simple
from reactpy_router import browser_router, route


@component
def root():
return simple.router(
return browser_router(
route("/", html.h1("Home Page 🏠")),
route("*", html.h1("Missing Link 🔗‍💥")),
)
Expand Down
9 changes: 3 additions & 6 deletions docs/examples/python/nested-routes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import TypedDict

from reactpy import component, html, run
from reactpy_router import link, route, simple
from reactpy_router import browser_router, link, route

message_data: list["MessageDataType"] = [
{"id": 1, "with": ["Alice"], "from": None, "message": "Hello!"},
Expand All @@ -17,7 +17,7 @@

@component
def root():
return simple.router(
return browser_router(
route("/", home()),
route(
"/messages",
Expand All @@ -40,10 +40,7 @@ def home():

@component
def all_messages():
last_messages = {
", ".join(msg["with"]): msg
for msg in sorted(message_data, key=lambda m: m["id"])
}
last_messages = {", ".join(msg["with"]): msg for msg in sorted(message_data, key=lambda m: m["id"])}
return html.div(
html.h1("All Messages 💬"),
html.ul(
Expand Down
5 changes: 2 additions & 3 deletions docs/examples/python/route-links.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from reactpy import component, html, run

from reactpy_router import link, route, simple
from reactpy_router import browser_router, link, route


@component
def root():
return simple.router(
return browser_router(
route("/", home()),
route("/messages", html.h1("Messages 💬")),
route("*", html.h1("Missing Link 🔗‍💥")),
Expand Down
9 changes: 3 additions & 6 deletions docs/examples/python/route-parameters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import TypedDict

from reactpy import component, html, run
from reactpy_router import link, route, simple
from reactpy_router import browser_router, link, route
from reactpy_router.core import use_params

message_data: list["MessageDataType"] = [
Expand All @@ -18,7 +18,7 @@

@component
def root():
return simple.router(
return browser_router(
route("/", home()),
route(
"/messages",
Expand All @@ -39,10 +39,7 @@ def home():

@component
def all_messages():
last_messages = {
", ".join(msg["with"]): msg
for msg in sorted(message_data, key=lambda m: m["id"])
}
last_messages = {", ".join(msg["with"]): msg for msg in sorted(message_data, key=lambda m: m["id"])}
return html.div(
html.h1("All Messages 💬"),
html.ul(
Expand Down
5 changes: 2 additions & 3 deletions docs/examples/python/use-params.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from reactpy import component, html

from reactpy_router import link, route, simple, use_params
from reactpy_router import browser_router, link, route, use_params


@component
Expand All @@ -11,7 +10,7 @@ def user():

@component
def root():
return simple.router(
return browser_router(
route(
"/",
html.div(
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/python/use-query.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from reactpy import component, html
from reactpy_router import link, route, simple, use_search_params
from reactpy_router import browser_router, link, route, use_search_params


@component
Expand All @@ -10,7 +10,7 @@ def search():

@component
def root():
return simple.router(
return browser_router(
route(
"/",
html.div(
Expand Down
8 changes: 4 additions & 4 deletions docs/src/learn/routers-routes-and-links.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ We include built-in components that automatically handle routing, which enable S

## Routers and Routes

The [`simple.router`][src.reactpy_router.simple.router] component is one possible implementation of a [Router][src.reactpy_router.types.Router]. Routers takes a series of [route][src.reactpy_router.route] objects as positional arguments and render whatever element matches the current location.
The [`browser_router`][src.reactpy_router.browser_router] component is one possible implementation of a [Router][src.reactpy_router.types.Router]. Routers takes a series of [route][src.reactpy_router.route] objects as positional arguments and render whatever element matches the current location.

!!! abstract "Note"

The current location is determined based on the browser's current URL and can be found
by checking the [`use_location`][reactpy.backend.hooks.use_location] hook.

Here's a basic example showing how to use `#!python simple.router` with two routes.
Here's a basic example showing how to use `#!python browser_router` with two routes.

=== "components.py"

Expand All @@ -21,9 +21,9 @@ Here's a basic example showing how to use `#!python simple.router` with two rout

Here we'll note some special syntax in the route path for the second route. The `#!python "*"` is a wildcard that will match any path. This is useful for creating a "404" page that will be shown when no other route matches.

### Simple Router
### Browser Router

The syntax for declaring routes with the [simple.router][src.reactpy_router.simple.router] is very similar to the syntax used by [`starlette`](https://www.starlette.io/routing/) (a popular Python web framework). As such route parameters are declared using the following syntax:
The syntax for declaring routes with the [`browser_router`][src.reactpy_router.browser_router] is very similar to the syntax used by [`starlette`](https://www.starlette.io/routing/) (a popular Python web framework). As such route parameters are declared using the following syntax:

```python linenums="0"
/my/route/{param}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/learn/simple-application.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p class="intro" markdown>

Here you'll learn the various features of `reactpy-router` and how to use them. These examples will utilize the [`reactpy_router.simple.router`][src.reactpy_router.simple.router].
Here you'll learn the various features of `reactpy-router` and how to use them. These examples will utilize the [`reactpy_router.browser_router`][src.reactpy_router.browser_router].

</p>

Expand Down
2 changes: 1 addition & 1 deletion docs/src/reference/router.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
::: src.reactpy_router.simple
::: src.reactpy_router.browser_router
6 changes: 4 additions & 2 deletions src/reactpy_router/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# the version is statically loaded by setup.py
__version__ = "0.1.1"

from . import simple
from . import routers
from .core import create_router, link, route, router_component, use_params, use_search_params
from .routers import browser_router
from .types import Route, RouteCompiler, RouteResolver

__all__ = (
Expand All @@ -11,10 +12,11 @@
"route",
"route",
"Route",
"routers",
"RouteCompiler",
"router_component",
"RouteResolver",
"simple",
"browser_router",
"use_params",
"use_search_params",
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from reactpy_router.core import create_router
from reactpy_router.types import Route

__all__ = ["router"]
__all__ = ["browser_router"]

ConversionFunc: TypeAlias = "Callable[[str], Any]"
ConverterMapping: TypeAlias = "dict[str, ConversionFunc]"
Expand Down Expand Up @@ -94,5 +94,7 @@ class ConversionInfo(TypedDict):
"""The supported conversion types"""


router = create_router(SimpleResolver)
"""The simple router"""
browser_router = create_router(SimpleResolver)
"""This is the recommended router for all ReactPy Router web projects.
It uses the DOM History API to update the URL and manage the history stack."""
# TODO: Check if this is true. If not, make it true.
16 changes: 8 additions & 8 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from reactpy import Ref, component, html, use_location
from reactpy.testing import DisplayFixture
from reactpy_router import link, route, simple, use_params, use_search_params
from reactpy_router import link, route, routers, use_params, use_search_params


async def test_simple_router(display: DisplayFixture):
Expand All @@ -18,7 +18,7 @@ def check_location():

@component
def sample():
return simple.router(
return routers.browser_router(
make_location_check("/a"),
make_location_check("/b"),
make_location_check("/c"),
Expand Down Expand Up @@ -50,7 +50,7 @@ def sample():
async def test_nested_routes(display: DisplayFixture):
@component
def sample():
return simple.router(
return routers.browser_router(
route(
"/a",
html.h1({"id": "a"}, "A"),
Expand Down Expand Up @@ -79,7 +79,7 @@ async def test_navigate_with_link(display: DisplayFixture):
@component
def sample():
render_count.current += 1
return simple.router(
return routers.browser_router(
route("/", link("Root", to="/a", id="root")),
route("/a", link("A", to="/b", id="a")),
route("/b", link("B", to="/c", id="b")),
Expand Down Expand Up @@ -110,7 +110,7 @@ def check_params():

@component
def sample():
return simple.router(
return routers.browser_router(
route(
"/first/{first:str}",
check_params(),
Expand Down Expand Up @@ -146,7 +146,7 @@ def check_query():

@component
def sample():
return simple.router(route("/", check_query()))
return routers.browser_router(route("/", check_query()))

await display.show(sample)

Expand All @@ -158,7 +158,7 @@ def sample():
async def test_browser_popstate(display: DisplayFixture):
@component
def sample():
return simple.router(
return routers.browser_router(
route("/", link("Root", to="/a", id="root")),
route("/a", link("A", to="/b", id="a")),
route("/b", link("B", to="/c", id="b")),
Expand Down Expand Up @@ -190,7 +190,7 @@ def sample():
async def test_relative_links(display: DisplayFixture):
@component
def sample():
return simple.router(
return routers.browser_router(
route("/", link("Root", to="/a", id="root")),
route("/a", link("A", to="/a/b", id="a")),
route("/a/b", link("B", to="../a/b/c", id="b")),
Expand Down
3 changes: 1 addition & 2 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import uuid

import pytest

from reactpy_router.simple import parse_path
from reactpy_router.routers import parse_path


def test_parse_path():
Expand Down