Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/liuhong1happy/similar-react-router

similar react-router
https://github.com/liuhong1happy/similar-react-router

react react-router similar-react-router

Last synced: about 2 months ago
JSON representation

similar react-router

Awesome Lists containing this project

README

        

# similar-react-router

[![Version](https://img.shields.io/npm/v/similar-react-router.svg)](https://www.npmjs.com/package/similar-react-router)
[![Downloads](https://img.shields.io/npm/dt/similar-react-router.svg)](https://www.npmjs.com/package/similar-react-router)

similar react-router

## 安装

npm install --save similar-react-router

## 用法

``` js
var React = reqiure('react');
var {Link,Route,Router,RouteHistory} = reqiure('simple-react-router');

var RootComponent = (props)=>{
return (


This is RootComponent!




  • 首页


  • 列表页


  • 详情页


  • 其它页面


{props.children}

)
}

var HomePage = (props)=>{
return (

{props.children}
)
}

var OtherPage = (props)=>{
return (

{"This is "+props.name+" page!"}
)
}

var HomeIndexPage = ()=>{
return (


This is HomeIndexPage!
)
}

var HomeListPage = ()=>{
return (


This is HomeListPage!
)
}

var HomeDetailPage = (props)=>{
return (


This is HomeDetailPage!
)
}

class RouterApp extends React.Component {
render(){
return (








)
}
}
```
## 示例项目

- [react-umeditor-example](https://github.com/liuhong1happy/react-umeditor-example)

## API

- Router 定义根路由,指定defaultRoute(默认路由)
- path 路由名称,这里指定为"/" `String`
- component 路由对应的组件 `React.Component`
- defaultRoute 默认路由 `String`
- Route 定义路由,可包含子路由,允许定义[:id]格式路由,默认允许传递[?id=xxx]方式
- path 路由名称,这里指定为"/" `String`
- component 路由对应的组件 `React.Component`
- children 子路由 `Array or `
- Link 简单路由链接
- to 跳转到的路由名称 `String`
- onClick 路由点击回调函数,内部已经实现路由跳转 `Function`
- anchor 是否渲染为a标签,否则就是span标签 `Boolean`
- RouteHistory 路由操纵,注意以下是属性或者方法,非props。
- pushHash 跳转 `Function`
- curHash 当前路由 `String`

## 特点

1. similar-react-router采用ES6写法,推荐使用webpack打包,loader采用babel-loader。

2. require引入react方式,可以兼容IE8。

3. 高度模仿react-router组件,采用hash实现,使用便捷。

4. 可以在redux中使用,看[这里](examples/redux)。

## 联系方式

Email: [liuhong1happy]([email protected])