vizz-router
Version:
Simple version of react router that only I'll be using (probably)
120 lines (85 loc) • 2.03 kB
Markdown
A simple, lightweight React router implementation for single-page applications.
```bash
npm install vizz-router
```
- 🚀 Lightweight and simple
- 📱 Browser history support
- 🔄 Programmatic navigation
- 🎯 Route matching
- 🔗 Link components
- ⚡ Built with React hooks
```jsx
import React from 'react';
import {
BrowserRouter,
Routes,
Route,
Link,
Navigate
} from 'vizz-router';
function App() {
return (
<BrowserRouter>
<nav>
<Link to="/">Home</Link>
<Link to="/about">About</Link>
</nav>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
</Routes>
</BrowserRouter>
);
}
function Home() {
return <h1>Home Page</h1>;
}
function About() {
return <h1>About Page</h1>;
}
```
Provides routing context using browser history API.
Container for route definitions.
Defines a route with a path and element to render.
```jsx
<Route path="/users/:id" element={<UserProfile />} />
```
Navigation component that updates the URL without page refresh.
```jsx
<Link to="/about">Go to About</Link>
```
Programmatically navigate to a different route.
```jsx
<Navigate to="/login" replace />
```
Access the current router context.
Get the navigate function for programmatic navigation.
```jsx
import { useNavigate } from 'vizz-router';
function MyComponent() {
const navigate = useNavigate();
const handleClick = () => {
navigate('/dashboard');
};
return <button onClick={handleClick}>Go to Dashboard</button>;
}
```
- React >= 16.8.0
MIT © Visalan H
---
*Made with ❤️ and probably too much coffee ☕*