no method named class
#3908
Unanswered
michaelgill1969
asked this question in
Q&A
Replies: 1 comment
|
There is also a router-context issue in the example: #[function_component(App)]
fn app() -> Html {
html! {
<BrowserRouter>
<Navbar />
// <Switch<Route> render={switch} />
</BrowserRouter>
}
}
#[function_component(Navbar)]
pub fn navbar() -> Html {
let current_route = use_route::<Route>();
let link_classes = |route: &Route| {
classes!(
"nav-link",
(current_route.as_ref() == Some(route)).then_some("active")
)
};
html! {
<nav class="navbar navbar-expand">
<ul class="nav navbar-nav justify-content-center">
<li class="nav-item">
<Link<Route>
to={Route::Home}
classes={link_classes(&Route::Home)}
>
{ "WELCOME" }
</Link<Route>>
</li>
<li class="nav-item">
<Link<Route>
to={Route::News}
classes={link_classes(&Route::News)}
>
{ "NEWS" }
</Link<Route>>
</li>
</ul>
</nav>
}
}Using The relevant source is |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I am trying to add an indication that a link is active in a navbar. When trying to edit the class method, I get the following error:
My code, which works fine without the class method, is as follows:
All reactions