0.0.1 • Published 3 years ago
oc-svelte-route v0.0.1
oc-svelte-route
A react-router-dom liked router library for svelte.
How to use
<div>
<Router path="/oc-route">
<Route path="/test" component={Layout}>
<Route path="/aa" component={RouterA} />
<Route path="/cc" />
</Route>
<Route path="/b" />
</Router>
</div>
<script lang="ts">
import { Router, Route } from 'oc-svelte-route';
import RouterA from './child/router-a.svelte';
import Layout from './layout.svelte';
</script>Hook
useHistory
this function can get history instance and you can callpush,backand so on.usage
import { useHistory } from 'oc-svelte-route'; const h = useHistory(); console.log(h);useLocation
this function can get history location and you canpath,stateand so on.usage
import { useLocation } from 'oc-svelte-route'; const l = useLocation(); console.log(l);useParams this function can get dynamic route's params and return a object.
usage
// /test/:id -> /test/124 import { useParams } from 'oc-svelte-route'; const p = useParams(); console.log(p); // {id: '124'}
0.0.1
3 years ago