Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/zeromake/zreact-router

fork from developit/preact-router
https://github.com/zeromake/zreact-router

Last synced: about 1 month ago
JSON representation

fork from developit/preact-router

Awesome Lists containing this project

README

        

# zreact-router

[![Travis Build Status](https://travis-ci.org/zeromake/zreact-router.svg?branch=master)](https://travis-ci.org/zeromake/zreact-router)
[![Coverage Status](https://coveralls.io/repos/github/zeromake/zreact-router/badge.svg?branch=master)](https://coveralls.io/github/zeromake/zreact-router?branch=master)

a simple router support react, preact, zreact.

copy from [preact-router](https://github.com/developit/preact-router)

## add support

1. animate support([preact-animate](https://github.com/zeromake/preact-animate))

``` jsx
import Animate from "preact-animate";
import { Route, DRouter } from "zreact-router";
function RootRouter() {
return
Home

Test


Home
}
path="/"
transitionName={{ enter: "fadeInLeft", leave: "fadeOutLeft" }}
>
Test
}
path="/test"
transitionName={{ enter: "fadeInRight", leave: "fadeOutRight" }}
>

;
}
```

`Router` children not support other tag

``` jsx
import { Router, Link } from "zreact-router";
function RootRouter() {
const Home = () =>

Home

;
const Test = () =>

Test


return

Home

Test





;
}
```
2. hash router support

``` jsx

import { Router, Link, LocationProvider, createHashSource, createHistory } from "zreact-router";

const source = createHashSource();
const history = createHistory(source, {mode: "hash"});

function RootRouter() {
const Home = () =>

Home

;
const Test = () =>

Test


return

Home

Test






;
}
```
3. delete global `navigate` export
``` js
import { globalHistory, createHashSource, createHistory } from "zreact-router";

// global `navigate`
const { navigate } = globalHistory;

// other global `navigate`
const hashHistory = createHistory(createHashSource());
const { navigate } = hashHistory
```

4. `Link` support `href` replace
``` jsx
import { Link } from "zreact-router";

const HomeLink = Home;
// href be equal to
const HomeLink = Home;
```

5. `Route` path params not assign `props` set on `props.params`
``` jsx
import { Router, Link } from "zreact-router";
function RootRouter() {
const Home = () =>

Home

;
const Test = (props) =>

{"Test: " + JSON.stringify(props.params)}


return

Home

Test





;
}
```

6. add `location.searchParams`

``` jsx
import { Router, Link } from "zreact-router";
function RootRouter() {
const Home = () =>

Home

;
const Test = (props) =>

{"Test: " + props.location.searchParams.get("test")}


return

Home

Test





;
}
```