Skip to content

Commit

Permalink
Add components: HashRouter BrowserRouter MemoryRouter.
Browse files Browse the repository at this point in the history
  • Loading branch information
vifird committed Dec 6, 2016
1 parent 415ef65 commit 7517d7b
Show file tree
Hide file tree
Showing 24 changed files with 263 additions and 162 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Expand Up @@ -6,7 +6,7 @@
"rules": {
"no-console": 0,
"no-unused-vars": 0,
"react/prop-types": 1,
"react/prop-types": 0,
"react/display-name": 0,
"react/wrap-multilines": 2
},
Expand Down
12 changes: 6 additions & 6 deletions docs/Route.md
Expand Up @@ -4,26 +4,26 @@
* normal component
* dynamic component
## Index Component
* Add `'rc-index'` property to Route component, when path is equals to parent component's path,this one will match and mount.
* Add `'index'` property to Route component, when path is equals to parent component's path,this one will match and mount.
```
<Route component={ User } path='/user'>
<Route rc-index component={ Info } path='/info'/>
<Route index component={ Info } path='/info'/>
<Route component={ Edit } path='/edit'/>
<Route component={ Article } path='/user'/>
</Route>
```
*`'rc-indexv` component can no use `'path'` property*
*`'indexv` component can no use `'path'` property*
## Miss Match Deal
* When no component is matched, we should show users something, such as `404` page. we support two way for this scene.
- use `'rc-miss'` property
- use `'miss'` property
```
<Route component={ User } path='/user'>
<Route component={ Edit } path='/edit'/>
<Route component={ Article } path='/user'/>
<Route component={ NotFound } rc-miss/>
<Route component={ NotFound } miss/>
</Route>
```
*`'rc-miss'` component can no use `'path'` property*
*`'miss'` component can no use `'path'` property*

- use `'*'` path property, and add it as the last child
```
Expand Down
2 changes: 1 addition & 1 deletion example/common/Footer.js
Expand Up @@ -5,7 +5,7 @@ export default class Footer extends React.Component {
return (
<footer className="navbar navbar-default navbar-fixed-bottom">
<div className="container-fluid text-center">
<h4 className="text-center">React-Control</h4>
<h4 className="text-center">react-flex-router</h4>
<p>Contact Us : Qiupeng Xie() 、 Zhipeng Zhang() 、 Bin Zhang(vifird@163.com)</p>
</div>
</footer>
Expand Down
4 changes: 2 additions & 2 deletions example/common/Header.js
@@ -1,5 +1,5 @@
import React from 'react'
import { Link,Control } from 'react-control'
import { Link,Control } from 'react-flex-router'
import './com.css'

export default class Header extends React.Component {
Expand All @@ -10,7 +10,7 @@ export default class Header extends React.Component {
<header className="navbar navbar-static-top navbar-inverse bs-docs-nav" id="top" role="banner">
<div className="container-fluid">
<div className="navbar-header">
<Link to="#/" className="navbar-brand">React-Control</Link>
<Link to="#/" className="navbar-brand">react-flex-router</Link>
</div>
<nav className="collapse navbar-collapse bs-navbar-collapse" role="navigation">
<ul className="nav navbar-nav">
Expand Down
34 changes: 13 additions & 21 deletions example/main/app.js
@@ -1,6 +1,6 @@
import React from 'react'
import ReactDOM from 'react-dom'
import { Router, Route, history } from 'react-control'
import { HashRouter, Route } from 'react-flex-router'

import Home from './pages/Home'

Expand All @@ -13,33 +13,25 @@ import AboutUs from './pages/AboutUs'

import Host from './pages/host/Host'

const historyConfig = {
type: 'hash',
basename: ''
}

class App extends React.Component {
constructor(...args) {
super(...args)
}

render() {
return (
<Router history={ history(historyConfig) }>

<Route component={Home} path="/"/>

<Route component={Products} path="/products">
<Route rc-index component={Enterprise} path="/ep"/>
<Route rc-miss component={Mobile}/>
<Route component={Detail} path="/item/:id" time={new Date().toLocaleString()}/>
</Route>
<HashRouter>
<div>
<Route component={Home} path="/"/>

<Route component={Host} path="/host" enterFilter={[ 'loginCheck', 'permitCheck' ]}/>
<Route component={Products} path="/products">
<Route index component={Enterprise} path="/ep"/>
<Route miss component={Mobile}/>
<Route component={Detail} path="/item/:id" time={new Date().toLocaleString()}/>
</Route>

<Route path="aboutus" component={AboutUs}/>
<Route component={Host} path="/host" enterFilter={[ 'loginCheck', 'permitCheck' ]}/>

</Router>
<Route lock path="aboutus" component={AboutUs}/>
</div>
</HashRouter>
)
}
}
Expand Down
8 changes: 4 additions & 4 deletions example/main/pages/host/Concerns.js
Expand Up @@ -6,10 +6,10 @@ export default class Concerns extends React.Component {
super(...args)
this.state = {
concerns: [
{ id:110, subject: 'React-Control , more than router of react.', time: 1457789912, user: 'Vifird', face: '/common/attach/user/1.jpg' },
{ id:110, subject: 'React-Control , more than router of react.', time: 1457789912, user: 'Lisa', face: '/common/attach/user/2.jpg' },
{ id:110, subject: 'React-Control , more than router of react.', time: 1457789912, user: 'John', face: '/common/attach/user/3.jpg' },
{ id:110, subject: 'React-Control , more than router of react.', time: 1457789912, user: 'Jasine', face: '/common/attach/user/4.jpg' }
{ id:110, subject: 'react-flex-router , more than router of react.', time: 1457789912, user: 'Vifird', face: '/common/attach/user/1.jpg' },
{ id:110, subject: 'react-flex-router , more than router of react.', time: 1457789912, user: 'Lisa', face: '/common/attach/user/2.jpg' },
{ id:110, subject: 'react-flex-router , more than router of react.', time: 1457789912, user: 'John', face: '/common/attach/user/3.jpg' },
{ id:110, subject: 'react-flex-router , more than router of react.', time: 1457789912, user: 'Jasine', face: '/common/attach/user/4.jpg' }
]
}
}
Expand Down
6 changes: 3 additions & 3 deletions example/main/pages/host/Host.js
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import Header from '../../../common/Header'
import Footer from '../../../common/Footer'
import LeftNav from './LeftNav'
import { Route } from 'react-control'
import { Route } from 'react-flex-router'
import HostInfo from './HostInfo'
import Edit from './Edit'
import Concerns from './Concerns'
Expand All @@ -16,9 +16,9 @@ export default class Host extends React.Component {
<LeftNav/>
<div className="col-md-10">

<Route rc-index component={HostInfo} path="/info"/>
<Route index component={HostInfo} path="/info"/>
<Route component={Edit} path="edit" leaveFilter={[ 'editLeave' ]}/>
<Route rc-miss path="concerns" component={Concerns}/>
<Route miss path="concerns" component={Concerns}/>

</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion example/main/pages/host/LeftNav.js
@@ -1,5 +1,5 @@
import React from 'react'
import { Link, Control } from 'react-control'
import { Link, Control } from 'react-flex-router'

export default class LeftNav extends React.Component {
render() {
Expand Down
2 changes: 1 addition & 1 deletion example/main/pages/products/LeftNav.js
@@ -1,5 +1,5 @@
import React from 'react'
import { Link, Control } from 'react-control'
import { Link, Control } from 'react-flex-router'

export default class LeftNav extends React.Component {

Expand Down
10 changes: 3 additions & 7 deletions example/temp/App.js
@@ -1,6 +1,6 @@
import React from 'react'
import ReactDOM from 'react-dom'
import { Router, Route, history, Link } from 'react-control'
import { HashRouter, Route, Link } from 'react-flex-router'

const historyConfig = {
type: 'hash',
Expand Down Expand Up @@ -32,13 +32,9 @@ class App extends React.Component {
super(...args)
}

componentDidMount() {

}

render() {
return (
<Router history={ history(historyConfig) }>
<HashRouter>
<span>
<ul>
<li><Link to="/">Home</Link></li>
Expand All @@ -60,7 +56,7 @@ class App extends React.Component {

</span>

</Router>
</HashRouter>
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion example/webpack.config.js
Expand Up @@ -41,7 +41,7 @@ module.exports = {

resolve: {
alias: {
'react-control': path.join(__dirname, '..', 'modules/index')
'react-flex-router': path.join(__dirname, '..', 'modules/index')
}
},

Expand Down
20 changes: 20 additions & 0 deletions jsconfig.json
@@ -0,0 +1,20 @@
/** vscode config */
{

"compilerOptions": {

"target": "ES6",

"module": "commonjs",

"experimentalDecorators" : true,

"lib": [
"es7",
"es2017.sharedmemory",
"es2017.object"
]

}

}
10 changes: 10 additions & 0 deletions modules/BrowserRouter.js
@@ -0,0 +1,10 @@
import Router from './Router'
import createBrowserHistory from 'history/createBrowserHistory'

export default class BrowserRouter extends Router {
}

BrowserRouter.prototype.createHistory = function () {
const { basename, hashType, getUserConfirmation } = this.props
return createBrowserHistory({ basename, hashType, getUserConfirmation })
}
10 changes: 10 additions & 0 deletions modules/HashRouter.js
@@ -0,0 +1,10 @@
import Router from './Router'
import createHashHistory from 'history/createHashHistory'

export default class HashRouter extends Router {
}

HashRouter.prototype.createHistory = function () {
const { basename, hashType, getUserConfirmation } = this.props
return createHashHistory({ basename, hashType, getUserConfirmation })
}
8 changes: 4 additions & 4 deletions modules/Link.js
@@ -1,5 +1,5 @@
import React from 'react'
import history from './history'
import { go } from './OuterControl'

/**
* replace the tag 'A', used to link to a new url
Expand Down Expand Up @@ -33,11 +33,11 @@ export default class Link extends React.Component {
if(to.indexOf('/') !== 0) {
to = `/${to}`
}
if(history.getHistory().location.pathname === to) {

if(this.context.history.location.pathname === to) {
return
}
history.getHistory().push(to)
history.getHistory().goForward()
go(to)
}

render() {
Expand Down
10 changes: 10 additions & 0 deletions modules/MemoryRouter.js
@@ -0,0 +1,10 @@
import Router from './Router'
import createMemoryHistory from 'history/createMemoryHistory'

export default class MemoryRouter extends Router {
}

MemoryRouter.prototype.createHistory = function () {
const { initialEntries, initialIndex, getUserConfirmation } = this.props
return createMemoryHistory({ initialEntries, initialIndex, getUserConfirmation })
}

0 comments on commit 7517d7b

Please sign in to comment.