Rasengan Logo
Rasengan Logo
  • Docs
  • Blog
  • Showcase
  • Support us
Using stable versionv1.2.0
Documentation
Packages
Templates
Rasengan UI Kit
Using stable versionv1.2.0
Documentation
Packages
Templates
Rasengan UI Kit

CORE CONCEPTS

Linking and Navigation

There are two ways to navigate between routes in Rasengan.js:

  • Using the <Link> Component
  • Using the useNavigate hook

This page will go through how to use each of these options, and dive deeper into how navigation works.

Using the Link Component

The <Link> component is a React component that allows you to navigate between routes in your application. It is the recommended way to navigate between routes in Rasengan.js.

Example 1: Basic usage

src/app/home.page.tsx
tsximport React from "react"; import { PageComponent, Link } from "rasengan"; const Home: PageComponent = () => { return ( <div> <h1>Home</h1> <Link to="/dashboard">Go to Dashboard</Link> </div> ); } Home.path = "/"; Home.metadata = { title: "Home", description: "Home Page", }; export default Home;

There are other option props available to <Link />, see the API Reference for more details.

Examples 2: Using dynamic routes

src/components/Posts.tsx
tsximport { Link } from "rasengan"; type Props = { posts: { id: number; title: string; }[]; }; export default function PostList({ posts }: Props) { return ( <div> {posts.map((post) => ( <div key={post.id}> <h2>{post.title}</h2> <Link to={`/post/${post.id}`}>Read More</Link> </div> ))} </div> ); };

Checking active links

src/components/ActiveLink.tsx
tsximport React from "react"; import { Link, useLocation } from "rasengan"; type Props = { to: string; children: React.ReactNode; }; export default function ActiveLink({ to, children }: Props) { const { pathname } = useLocation(); return ( <Link to={to} className={`${pathname === to ? "active" : ""}`}> {children} </Link> ); }

Scrolling to an id

tsx<Link to="/admin/dashboard#statistics">Statistics</Link>

useNavigate hook

The useNavigate hook is used to change the current route in your application. It returns a function that you can call to navigate to a different route.

Example 1: Basic usage

src/app/home.page.tsx
tsximport React from "react"; import { PageComponent, useNavigate } from "rasengan"; const Home: PageComponent = () => { const navigate = useNavigate(); return ( <div> <h1>Home</h1> <button onClick={() => navigate("/dashboard")}>Go to Dashboard</button> </div> ); } Home.path = "/"; Home.metadata = { title: "Home", description: "Home Page", }; export default Home;

For a full list of useNavigate options, see the API reference on the documentation of React Router.

Example 2: Logout with navigation

src/components/LogoutButton.tsx
tsximport React from "react"; import { useNavigate } from "rasengan"; export default function LogoutButton() { const navigate = useNavigate(); const logout = async () => { try { // Logout logic Here navigate("/sign-in"); } catch (error) { console.error(error); } } return ( <button onClick={logout}>Logout</button> ) }
File-Based Routing
Dynamic Routes

ON THIS PAGE

Using the Link Component
Example 1: Basic usage
Examples 2: Using dynamic routes
useNavigate hook
Example 1: Basic usage
Example 2: Logout with navigation
Rasengan Logo
Rasengan Logo

Resources

  • Docs
  • Packages
  • Blog
  • Showcase
  • Support us

Community

  • Github
  • X (Twitter)

Subscribe to the Newsletter

Stay informed to the news about rasengan.js including new releases, events, etc...

© 2024-2026 Rasengan Labs, All rights reserved.