Struct leptos_router::RouteProps

source ·
pub struct RouteProps<E, F, P>
where E: IntoView, F: Fn() -> E + 'static, P: Display,
{ pub path: P, pub view: F, pub ssr: SsrMode, pub methods: &'static [Method], pub data: Option<Loader>, pub trailing_slash: Option<TrailingSlash>, pub children: Option<Children>, }
Expand description

Props for the Route component.

Describes a portion of the nested layout of the app, specifying the route it should match, the element it should display, and data that should be loaded alongside the route.

§Required Props

  • path: [P]
    • The path fragment that this route should match. This can be static (users), include a parameter (:id) or an optional parameter (:id?), or match a wildcard (user/*any).
  • view: [F]
    • The view that should be shown when this route is matched. This can be any function that returns a type that implements IntoView (like || view! { <p>"Show this"</p> }) or || view! { <MyComponent/> } or even, for a component with no props, MyComponent).

§Optional Props

  • ssr: SsrMode
    • The mode that this route prefers during server-side rendering. Defaults to out-of-order streaming.
  • methods: [&'static [Method]]
    • The HTTP methods that this route can handle (defaults to only GET).
  • data: impl Into<Loader>
    • A data-loading function that will be called when the route is matched. Its results can be accessed with use_route_data.
  • trailing_slash: TrailingSlash
    • How this route should handle trailing slashes in its path. Overrides any setting applied to crate::components::Router. Serves as a default for any inner Routes.
  • children: Children
    • children may be empty or include nested routes.

Fields§

§path: P

The path fragment that this route should match. This can be static (users), include a parameter (:id) or an optional parameter (:id?), or match a wildcard (user/*any).

§view: F

The view that should be shown when this route is matched. This can be any function that returns a type that implements IntoView (like || view! { <p>"Show this"</p> }) or || view! { <MyComponent/> } or even, for a component with no props, MyComponent).

§ssr: SsrMode

The mode that this route prefers during server-side rendering. Defaults to out-of-order streaming.

§methods: &'static [Method]

The HTTP methods that this route can handle (defaults to only GET).

§data: Option<Loader>

A data-loading function that will be called when the route is matched. Its results can be accessed with use_route_data.

§trailing_slash: Option<TrailingSlash>

How this route should handle trailing slashes in its path. Overrides any setting applied to crate::components::Router. Serves as a default for any inner Routes.

§children: Option<Children>

children may be empty or include nested routes.

Implementations§

source§

impl<E, F, P> RouteProps<E, F, P>
where E: IntoView, F: Fn() -> E + 'static, P: Display,

source

pub fn builder() -> RoutePropsBuilder<E, F, P, ((), (), (), (), (), (), ())>

Create a builder for building RouteProps. On the builder, call .path(...), .view(...), .ssr(...)(optional), .methods(...)(optional), .data(...)(optional), .trailing_slash(...)(optional), .children(...)(optional) to set the values of the fields. Finally, call .build() to create the instance of RouteProps.

Trait Implementations§

source§

impl<E, F, P> IntoView for RouteProps<E, F, P>
where E: IntoView, F: Fn() -> E + 'static, P: Display,

source§

fn into_view(self) -> View

Converts the value into View.

Auto Trait Implementations§

§

impl<E, F, P> Freeze for RouteProps<E, F, P>
where P: Freeze, F: Freeze,

§

impl<E, F, P> !RefUnwindSafe for RouteProps<E, F, P>

§

impl<E, F, P> !Send for RouteProps<E, F, P>

§

impl<E, F, P> !Sync for RouteProps<E, F, P>

§

impl<E, F, P> Unpin for RouteProps<E, F, P>
where P: Unpin, F: Unpin,

§

impl<E, F, P> !UnwindSafe for RouteProps<E, F, P>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more