oc-svelte-route
v0.0.1
Published
<div align="center"> <img src='https://github.com/southorange1228/oc-svelte-route/blob/master/public/orange.svg' width='200px' height='200px'> </div>
Downloads
2
Readme
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
,back
and 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
,state
and 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'}