Reference
Core functionality for the reactpy-router package.
create_router(compiler)
A decorator that turns a route compiler into a router
Source code in reactpy_router/core.py
35 36 37 38 39 40 41 |
|
link(*children, to, **attributes)
A component that renders a link to the given path
Source code in reactpy_router/core.py
74 75 76 77 78 79 80 81 82 83 |
|
route(path, element, *routes)
Create a route with the given path, element, and child routes
Source code in reactpy_router/core.py
30 31 32 |
|
router_component(*routes, compiler)
A component that renders the first matching route using the given compiler
Source code in reactpy_router/core.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
use_params()
Get parameters from the currently matching route pattern
Source code in reactpy_router/core.py
86 87 88 |
|
use_query(keep_blank_values=False, strict_parsing=False, errors='replace', max_num_fields=None, separator='&')
See :func:urllib.parse.parse_qs
for parameter info.
Source code in reactpy_router/core.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
A simple router implementation for ReactPy
CONVERSION_TYPES: dict[str, ConversionInfo] = {'str': {'regex': '[^/]+', 'func': str}, 'int': {'regex': '\\d+', 'func': int}, 'float': {'regex': '\\d+(\\.\\d+)?', 'func': float}, 'uuid': {'regex': '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}', 'func': uuid.UUID}, 'path': {'regex': '.+', 'func': str}}
module-attribute
The supported conversion types
router = create_router(SimpleResolver)
module-attribute
The simple router
ConversionInfo
Bases: TypedDict
Information about a conversion type
Source code in reactpy_router/simple.py
63 64 65 66 67 68 69 |
|
func: ConversionFunc
instance-attribute
The function to convert the matched string to the expected type
regex: str
instance-attribute
The regex to match the conversion type
SimpleResolver
A simple route resolver that uses regex to match paths
Source code in reactpy_router/simple.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
Types for reactpy_router
Route
dataclass
A route that can be matched against a path
Source code in reactpy_router/types.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
element: Any = field(hash=False)
class-attribute
instance-attribute
The element to render if the path matches
path: str
instance-attribute
The path to match against
routes: Sequence[Self]
instance-attribute
Child routes
RouteCompiler
Bases: Protocol[R]
Compile a route into a resolver that can be matched against a path
Source code in reactpy_router/types.py
42 43 44 45 46 |
|
RouteResolver
Bases: Protocol
A compiled route that can be matched against a path
Source code in reactpy_router/types.py
49 50 51 52 53 54 55 56 57 |
|
key: Key
property
Uniquely identified this resolver
resolve(path)
Return the path's associated element and path params or None
Source code in reactpy_router/types.py
56 57 |
|
Router
Bases: Protocol[R]
Return a component that renders the first matching route
Source code in reactpy_router/types.py
35 36 37 38 39 |
|