import React from 'react'; import { Routes, Route, useNavigate, useRouteContext, useLocation } from '@openwebf/react-router'; // Navigation Menu component function NavigationMenu() { const { navigate, canPop, pop } = useNavigate(); const location = useLocation(); const handleBack = () => { if (canPop()) { pop(); } else { console.log('Cannot go back, already at root'); } }; return ( ); } // Home page function HomePage() { const { navigate, popAndPush, pushAndRemoveUntil } = useNavigate(); const handleNavigateWithState = () => { navigate('/about', { state: { message: 'Hello from Home!', timestamp: new Date().toISOString() } }); }; const handlePopAndPush = async () => { await popAndPush('/contact', { from: 'home-pop-push' }); }; const handlePushAndRemoveUntil = async () => { // Push contact and remove all routes until home await pushAndRemoveUntil('/contact', '/', { cleared: true }); }; return (
Welcome to the home page!
Learn more about us!
{location.state?.message && (Received state from location:
{JSON.stringify(location.state, null, 2)}
Get in touch with us!
{params?.replacedFrom && (You were redirected from: {params.replacedFrom}
)}