import React from 'react';
import {
Router,
Routes,
Route,
Link,
Outlet,
useNavigate,
useLocation,
useParams
} from '@openwebf/react-router';
// Home component
function Home() {
const navigate = useNavigate();
const handleNavigate = () => {
navigate('/about', { state: { from: 'home' } });
};
return (
Home
Welcome to the home page!
);
}
// About component
function About() {
const location = useLocation();
return (
About
This is the about page.
{location.state?.from && (
You came from: {location.state.from}
)}
);
}
// User profile component
function UserProfile() {
const { id } = useParams<{ id: string }>();
return (
User Profile
User ID: {id}
);
}
// Users component with nested routes
function Users() {
return (
);
}
// Layout component (Note: Navigation should be visible on all routes)
function Layout() {
const location = useLocation();
return (
);
}
// Contact component demonstrating replace navigation
function Contact() {
const navigate = useNavigate();
const handleReplace = () => {
navigate('/', { replace: true });
};
return (
Contact
Contact us at: example@email.com
);
}
// Not Found component
function NotFound() {
return (
404 - Not Found
The page you're looking for doesn't exist.
Go back to Home
);
}
// Main App component
export default function App() {
return (
}>
} />
} />
}>
} />
} />
} />
);
}