T8 React Router
Navigation
The route navigation API is largely aligned with the similar native JS APIs familiar to most web developers, such as <a href="/x">
and window.location
:
+ import { A, useRoute } from "@t8/react-router";
let UserNav = ({ signedIn }) => {
+ let { route } = useRoute();
let handleClick = () => {
- window.location.assign(signedIn ? "/profile" : "/login");
+ route.assign(signedIn ? "/profile" : "/login");
};
return (
<nav>
- <a href="/">Home</a>
+ <A href="/">Home</A>
<button onClick={handleClick}>Profile</button>
</nav>
);
};
🔹 The route
object has: .assign(url)
, .replace(url)
, .reload()
, .href
, .pathname
, .search
, .hash
, .back()
, .forward()
, .go(delta)
— similar to the built-in APIs of window.location
and history
carried over to route-based SPA navigation.
🔹 A route link component can be switched to the replace mode by having the data-navigation-mode="replace"
attribute.
🔹 Like the route link <A>
corresponds to the HTML link tag <a>
, the route link <Area>
corresponds to the HTML link tag <area>
.
← Routing | Middleware →