0.0.1 • Published 2 years ago

oc-svelte-route v0.0.1

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

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 call push,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 can path,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'}