Add example protected route to project

This commit is contained in:
Marko Korhonen 2020-05-08 09:35:28 +03:00
parent 1e83393ad6
commit fb5aa5ee5a
No known key found for this signature in database
GPG key ID: 911B85FBC6003FE5
9 changed files with 161 additions and 36 deletions

View file

@ -6,7 +6,7 @@ extern crate web_logger;
mod component;
pub mod utils;
use component::login::LoginComponent;
use component::{login::LoginComponent, protected::ProtectedComponent};
use yew::prelude::*;
use yew::virtual_dom::VNode;
use yew_router::{prelude::*, switch::Permissive, Switch};
@ -37,6 +37,10 @@ impl Component for App {
fn view(&self) -> VNode {
html! {
<div>
<nav class="menu",>
<RouterButton<AppRoute> route=AppRoute::Login> {"Kirjautuminen"} </RouterButton<AppRoute>>
<RouterButton<AppRoute> route=AppRoute::Root> {"Suojattu data"} </RouterButton<AppRoute>>
</nav>
<Router<AppRoute>
render = Router::render(|switch: AppRoute| {
match switch {
@ -44,7 +48,7 @@ impl Component for App {
AppRoute::PageNotFound(Permissive(None)) => html!{"Page not found"},
AppRoute::PageNotFound(Permissive(Some(missed_route))) => html!{format!("Page '{}' not found", missed_route)},
AppRoute::Root => {
html!{"hello there!"}
html!{<ProtectedComponent />}
},
}
})