1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! Navigation-oriented hooks shared by Orbital shell components.
//!
//! These helpers are intentionally small and router-focused. They let UI components
//! such as side navigation or tabs reactively determine whether a
//! route should be considered active.
//!
//! ## Example
//!
//! ```rust,ignore
//! use leptos::prelude::*;
//! use orbital::nav::use_route_active;
//!
//! #[component]
//! fn CounterNavLink() -> impl IntoView {
//! let is_active = use_route_active("/counter", false);
//!
//! view! {
//! <a class:active=move || is_active.get() href="/counter">
//! "Counter"
//! </a>
//! }
//! }
//! ```
use *;
use use_location;
/// Reactive hook that returns whether the given path matches the current location.
///
/// When `exact` is true, only an exact match counts. When `exact` is false (default), any path that starts with the given prefix matches.
///
/// The hook normalises the current pathname by stripping a trailing slash so that `/counter` and `/counter/` are treated identically.
///
/// This is primarily intended for navigation items that should stay highlighted while the user browses nested routes under the same section.