Solid Navigator is a library that is inspired by vue-router and @solidjs/router.
Install it:
npm i solid-navigator
# or
pnpm add solid-navigatorUse it:
import{Router,Route,Outlet,A,Navigate,useNavigate,useLocation,useParams,useMatch,useSearchParams}from'solid-navigator'constnavigate=useNavigate();navigate("/app",{replace: true})// path: /app?id=1constlocation=useLocation();{
query: {id: string} search: string
pathname: string
hash: string}// path: /chats/:idconstparams=useParams<{id: string}>();{id: string}// path: /chats/1234constmatch=useMatch(()=>"/chats/1234");{
path: "/chats/1234"
params: {}}|null// path: /chats?id=1234const[params,setParams]=useSearchParams();params={id: "1234"}|nullsetParams({id: "5678",hello: "Bye"})// path: /chats?id=5678&hello=ByeconstRoot=()=>{return(<div><h1>Header</h1><Outlet/></div>)}constMain=()=>{return(<Routerroot={Root}>
// Routes go here
</Router>)}constMain=()=>{constAppComponent=()=>{return(<div><div><Outletname="drawer"/></div><div><Outletname="content"/></div></div>)}return(<Routerroot={Root}><Routepath="/"component={AppComponent}><Routecomponents={{drawer: Drawer,content: Content}}/></Route></Router>)}constApp=()=>{return(<Ahref="/"replace/>)}constApp=()=>{return(<Navigateto="/"/>)}