Struct percy_router::prelude::Router
source · pub struct Router { /* private fields */ }
Expand description
Holds all of the routes for an application.
A typical use case is that when we want to move to a new route (such as after clicking on an anchor tag) we’ll query our router to see if the new route matches any of our route definitions.
Then if we find a matching route we’ll return it.
Implementations§
source§impl Router
impl Router
sourcepub fn new(route_handlers: Vec<Rc<dyn RouteHandler>>) -> Self
pub fn new(route_handlers: Vec<Rc<dyn RouteHandler>>) -> Self
Create a new Router.
ⓘ
let router = Router::new(create_routes![index_route, products_route]);
sourcepub fn matching_route_handler(
&self,
incoming_route: &str
) -> Option<&Rc<dyn RouteHandler>>
pub fn matching_route_handler(
&self,
incoming_route: &str
) -> Option<&Rc<dyn RouteHandler>>
Return the matching RouteHandler given some incoming_route
sourcepub fn view(&self, incoming_route: &str) -> Option<VirtualNode>
pub fn view(&self, incoming_route: &str) -> Option<VirtualNode>
Get the first route in our routes vector view that handles this incoming_route
and return the view for that route.
You’ll typically call this when trying to render the correct view based on the page URL or after clicking on an anchor tag.