|
@@ -161,6 +161,7 @@ class App(Base):
|
|
self,
|
|
self,
|
|
component: Union[Component, ComponentCallable],
|
|
component: Union[Component, ComponentCallable],
|
|
path: Optional[str] = None,
|
|
path: Optional[str] = None,
|
|
|
|
+ route: Optional[str] = None,
|
|
title: str = constants.DEFAULT_TITLE,
|
|
title: str = constants.DEFAULT_TITLE,
|
|
description: str = constants.DEFAULT_DESCRIPTION,
|
|
description: str = constants.DEFAULT_DESCRIPTION,
|
|
image=constants.DEFAULT_IMAGE,
|
|
image=constants.DEFAULT_IMAGE,
|
|
@@ -172,22 +173,30 @@ class App(Base):
|
|
|
|
|
|
Args:
|
|
Args:
|
|
component: The component to display at the page.
|
|
component: The component to display at the page.
|
|
- path: The path to display the component at.
|
|
|
|
|
|
+ path: (deprecated) The path to the component.
|
|
|
|
+ route: The route to display the component at.
|
|
title: The title of the page.
|
|
title: The title of the page.
|
|
description: The description of the page.
|
|
description: The description of the page.
|
|
image: The image to display on the page.
|
|
image: The image to display on the page.
|
|
"""
|
|
"""
|
|
- # If the path is not set, get it from the callable.
|
|
|
|
- if path is None:
|
|
|
|
|
|
+ if path is not None:
|
|
|
|
+ utils.deprecate(
|
|
|
|
+ "The `path` argument is deprecated for `add_page`. Use `route` instead."
|
|
|
|
+ )
|
|
|
|
+ route = path
|
|
|
|
+
|
|
|
|
+ # If the route is not set, get it from the callable.
|
|
|
|
+ if route is None:
|
|
assert isinstance(
|
|
assert isinstance(
|
|
component, Callable
|
|
component, Callable
|
|
- ), "Path must be set if component is not a callable."
|
|
|
|
- path = component.__name__
|
|
|
|
|
|
+ ), "Route must be set if component is not a callable."
|
|
|
|
+ route = component.__name__
|
|
|
|
|
|
- # Check if the path given is valid
|
|
|
|
- utils.verify_path_validity(path)
|
|
|
|
|
|
+ # Check if the route given is valid
|
|
|
|
+ utils.verify_route_validity(route)
|
|
|
|
|
|
- self.state.setup_dynamic_args(utils.get_path_args(path))
|
|
|
|
|
|
+ # Apply dynamic args to the route.
|
|
|
|
+ self.state.setup_dynamic_args(utils.get_route_args(route))
|
|
|
|
|
|
# Generate the component if it is a callable.
|
|
# Generate the component if it is a callable.
|
|
component = component if isinstance(component, Component) else component()
|
|
component = component if isinstance(component, Component) else component()
|
|
@@ -198,7 +207,8 @@ class App(Base):
|
|
)
|
|
)
|
|
|
|
|
|
# Format the route.
|
|
# Format the route.
|
|
- route = utils.format_route(path)
|
|
|
|
|
|
+ route = utils.format_route(route)
|
|
|
|
+
|
|
# Add the page.
|
|
# Add the page.
|
|
self._check_routes_conflict(route)
|
|
self._check_routes_conflict(route)
|
|
self.pages[route] = component
|
|
self.pages[route] = component
|
|
@@ -209,7 +219,7 @@ class App(Base):
|
|
Based on conflicts that NextJS would throw if not intercepted.
|
|
Based on conflicts that NextJS would throw if not intercepted.
|
|
|
|
|
|
Raises:
|
|
Raises:
|
|
- ValueError: exception showing which conflict exist with the path to be added
|
|
|
|
|
|
+ ValueError: exception showing which conflict exist with the route to be added
|
|
|
|
|
|
Args:
|
|
Args:
|
|
new_route: the route being newly added.
|
|
new_route: the route being newly added.
|
|
@@ -233,7 +243,7 @@ class App(Base):
|
|
and utils.catchall_prefix(route) == utils.catchall_prefix(new_route)
|
|
and utils.catchall_prefix(route) == utils.catchall_prefix(new_route)
|
|
):
|
|
):
|
|
raise ValueError(
|
|
raise ValueError(
|
|
- f"You cannot use multiple catchall for the same dynamic path ({route} !== {new_route})"
|
|
|
|
|
|
+ f"You cannot use multiple catchall for the same dynamic route ({route} !== {new_route})"
|
|
)
|
|
)
|
|
|
|
|
|
def add_custom_404_page(self, component, title=None, image=None, description=None):
|
|
def add_custom_404_page(self, component, title=None, image=None, description=None):
|
|
@@ -297,9 +307,9 @@ class App(Base):
|
|
|
|
|
|
# Compile the pages.
|
|
# Compile the pages.
|
|
custom_components = set()
|
|
custom_components = set()
|
|
- for path, component in self.pages.items():
|
|
|
|
|
|
+ for route, component in self.pages.items():
|
|
component.add_style(self.style)
|
|
component.add_style(self.style)
|
|
- compiler.compile_page(path, component, self.state)
|
|
|
|
|
|
+ compiler.compile_page(route, component, self.state)
|
|
|
|
|
|
# Add the custom components from the page to the set.
|
|
# Add the custom components from the page to the set.
|
|
custom_components |= component.get_custom_components()
|
|
custom_components |= component.get_custom_components()
|