Adding the router to your application

In this chapter, we will learn how to add the router to our app. By itself, this

Make sure you added the dioxus-router dependency as explained in theintroduction.

In most cases, we want to add the router to the root component of our app. This

First, we define the router with the router macro:

src/first_route.rs
#![allow(non_snake_case)]
use dioxus::prelude::*;
use dioxus_router::prelude::*;

/// An enum of all of the possible routes in the app.
#[derive(Routable, Clone)]
enum Route {
    // The home page is at the / route
    #[route("/")]
    Home {},
}

Then we render the router with the Router]

src/first_route.rs
fn App() -> Element {
    rsx! { Router::<Route> {} }
}