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 {
|
enum Route {
|
||||||
#[at("/")]
|
#[at("/")]
|
||||||
Index,
|
Index,
|
||||||
|
#[at("/login")]
|
||||||
|
Login,
|
||||||
#[at("/404")]
|
#[at("/404")]
|
||||||
#[not_found]
|
#[not_found]
|
||||||
NotFound,
|
NotFound,
|
||||||
|
|
@ -25,7 +27,10 @@ fn App() -> Html {
|
||||||
fn switch(route: Route) -> Html {
|
fn switch(route: Route) -> Html {
|
||||||
match route {
|
match route {
|
||||||
Route::Index => html! {
|
Route::Index => html! {
|
||||||
"Index"
|
<Index />
|
||||||
|
},
|
||||||
|
Route::Login => html! {
|
||||||
|
"Login"
|
||||||
},
|
},
|
||||||
Route::NotFound => html! {
|
Route::NotFound => html! {
|
||||||
"Page not found"
|
"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() {
|
fn main() {
|
||||||
console_log::init_with_level(Level::Debug).unwrap();
|
console_log::init_with_level(Level::Debug).unwrap();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue