Redirect to login page if not currently logged in
This commit is contained in:
parent
54f1c3233f
commit
062a749d59
1 changed files with 20 additions and 1 deletions
|
|
@ -6,6 +6,8 @@ use yew_router::prelude::*;
|
|||
enum Route {
|
||||
#[at("/")]
|
||||
Index,
|
||||
#[at("/login")]
|
||||
Login,
|
||||
#[at("/404")]
|
||||
#[not_found]
|
||||
NotFound,
|
||||
|
|
@ -25,7 +27,10 @@ fn App() -> Html {
|
|||
fn switch(route: Route) -> Html {
|
||||
match route {
|
||||
Route::Index => html! {
|
||||
"Index"
|
||||
<Index />
|
||||
},
|
||||
Route::Login => html! {
|
||||
"Login"
|
||||
},
|
||||
Route::NotFound => html! {
|
||||
"Page not found"
|
||||
|
|
@ -33,6 +38,20 @@ fn switch(route: Route) -> Html {
|
|||
}
|
||||
}
|
||||
|
||||
#[function_component]
|
||||
fn Index() -> Html {
|
||||
let token = use_state(|| None::<String>);
|
||||
|
||||
match &*token {
|
||||
Some(_) => html! {
|
||||
"Index"
|
||||
},
|
||||
None => html! {
|
||||
<Redirect<Route> to={Route::Login} />
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
console_log::init_with_level(Level::Debug).unwrap();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue