Skip to content

Commit

Permalink
Merge branch '2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
gxlmyacc committed Dec 25, 2019
2 parents 3bac06d + 66dcdf3 commit a8d4165
Show file tree
Hide file tree
Showing 34 changed files with 7,814 additions and 2,973 deletions.
10 changes: 5 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ module.exports = {
],
plugins: [],
settings: {
"import/resolver": {
webpack: {
config: './build/webpack-dev.config.js'
},
},
// "import/resolver": {
// webpack: {
// config: './build/webpack-dev.config.js'
// },
// },
react: {
version: require('./package.json').dependencies.react,
},
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ analyzer/
.DS_Store
*/.DS_Store
plugin/
esm
es
drawer/esm
drawer/es

32 changes: 13 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# `react-view-router`
# react-view-router@2.x

[![NPM version](https://img.shields.io/npm/v/react-view-router.svg?style=flat)](https://npmjs.com/package/react-view-router)
[![NPM downloads](https://img.shields.io/npm/dm/react-view-router.svg?style=flat)](https://npmjs.com/package/react-view-router)

> Route configuration component for `react-router-dom`. `react-view-router` is just a `react-router-dom@5` wrapper that can write routing configuration like [vue-router](https://router.vuejs.org/guide/#javascript) in react. see: [Nested Routes](https://router.vuejs.org/guide/essentials/nested-routes.html)
> A Route manager for `react` can write routing configuration like [vue-router](https://router.vuejs.org/guide/#javascript) in react. see: [Nested Routes](https://router.vuejs.org/guide/essentials/nested-routes.html)
> Unlike 1.x, `react-view-router@2.x` does not depend on the [react-router](https://github.com/ReactTraining/react-router) Library
> see [react-view-router@1.x](https://github.com/gxlmyacc/react-view-router/tree/1.x)
## Installation

Expand Down Expand Up @@ -135,9 +139,6 @@ export default useRouteGuards(HomeMainSomeIndex, {
},
beforeRouteUpdate(to, from) {

},
afterRouteEnter(to, from) {

},
afterRouteLeave(to, from) {

Expand Down Expand Up @@ -221,7 +222,6 @@ const routes = normalizeRoutes([
beforeEnter(to, from, next) { next(); }
beforeLeave(to, from, next) { next(); }
beforeUpdate(to, from) {}
afterEnter(to, from) {}
afterLeave(to, from) {}
}
]
Expand Down Expand Up @@ -256,13 +256,6 @@ const routes = normalizeRoutes([
- `queryProps` boolean or object `{ aa: Number, bb: String, cc: Boolean }`, Pass url query as props into route component.
- `guards` the route guards, see:[Per-Route Guard](https://router.vuejs.org/guide/advanced/navigation-guards.html#global-after-hooks)

### Route Component Props

Includes all props from `react-router-dom` and the following props.

- `route` current route infos.
- `parent` the RouterView instance.

### RouterView Props

- `name` Use for `Named Views`, see [vue-router instructions](https://router.vuejs.org/guide/essentials/named-views.html#nested-named-views)
Expand All @@ -275,9 +268,6 @@ Includes all props from `react-router-dom` and the following props.
- `RouterView.indexOf(route: String|Object): Number` check `route` is in RouterView, like `Array.indexOf`
- `RouterView.remove(route: String|Object): Object` remove `route` from RouterView, return `removed route` or `undefined`

### RouterLink Component
- `RouterLink` is `NavLink` component that in `react-router-dom`, just re-exported.

### ReactViewRouter Props
- `currentRoute` current matched route infos:
```javascript
Expand Down Expand Up @@ -310,7 +300,9 @@ Includes all props from `react-router-dom` and the following props.
/* others: React.Component */
}
// the RouterView instance that matched this route config if found.
viewInstance: RouterView
viewInstances: {
default: RouterView
}
}
...,
routeN
Expand All @@ -329,6 +321,9 @@ Includes all props from `react-router-dom` and the following props.
```
see: [Route Object Properties](https://router.vuejs.org/api/#route-object-properties)

### ReactViewRouter instance Props
- `RouterLink` a `NavLink` component like `route-link` in `vue-router`.

### ReactViewRouter instance Methods
- `beforeEach` [global Before Guards](https://router.vuejs.org/guide/advanced/navigation-guards.html#global-before-guards)
- `afterEach` [global After Guards](https://router.vuejs.org/guide/advanced/navigation-guards.html#global-after-hooks)
Expand Down Expand Up @@ -390,7 +385,6 @@ function normalizeLocation(to, route?) {}
function isLocation(v) {}
```
- `withRouter` just re-export, see: [withRouter](https://reacttraining.com/react-router/web/api/withRouter)
- `matchPath` just re-export, see: [matchPath](https://reacttraining.com/react-router/web/api/matchPath)
## NOTE
Expand All @@ -409,7 +403,7 @@ function isLocation(v) {}
```
otherwise, webpack will package both `history` and `history-fix` into the target js file.
2. if route component is `Class Component` (not `Function Component`), then `this` variable in `afterRouteEnter`, `beforeRouteUpdate`,`beforeRouteLeave`,`afterRouteLeave` Component Guards will be that component instance;
2. if route component is `Class Component` (not `Function Component`), then `this` variable in `beforeRouteUpdate`,`beforeRouteLeave`,`afterRouteLeave` Component Guards will be that component instance;
## License
Expand Down
8 changes: 4 additions & 4 deletions build/webpack-base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ module.exports = function (options) {
]
},
externals: [
'history-fix',
'react',
'mini-create-react-context',
'prop-types',
'react-is',
'regenerator-runtime',
'hoist-non-react-statics'
'path-to-regexp',
'prop-types',
'regenerator-runtime'
],
resolve: {
symlinks: false,
Expand Down
3 changes: 0 additions & 3 deletions demo/src/views/component/home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ export default useRouteGuards(HomeIndex, {
beforeRouteUpdate(to, from) {
console.log('HomeIndex beforeRouteUpdate', to, from);
},
afterRouteEnter(to, from) {
console.log('HomeIndex afterRouteEnter', to, from);
},
afterRouteLeave(to, from) {
console.log('HomeIndex afterRouteLeave', to, from);
},
Expand Down
9 changes: 6 additions & 3 deletions demo/src/views/component/home/main/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import React from 'react';
import { RouterView, useRouteGuards } from 'react-view-router';
import { RouterLink } from 'router';

function HomeMainIndex() {
return (
<div>
<h1>HomeMainIndex</h1>
<div className="nav">
<RouterLink to="some" append>some</RouterLink>
&nbsp;
<RouterLink to="other" append>other</RouterLink>
</div>
<RouterView />
<RouterView name="footer" />
</div>
Expand All @@ -24,9 +30,6 @@ export default useRouteGuards(HomeMainIndex, {
beforeRouteUpdate(to, from) {
console.log('HomeMainIndex beforeRouteUpdate', to, from);
},
afterRouteEnter(to, from) {
console.log('HomeMainIndex afterRouteEnter', to, from);
},
afterRouteLeave(to, from) {
console.log('HomeMainIndex afterRouteLeave', to, from);
},
Expand Down
3 changes: 0 additions & 3 deletions demo/src/views/component/home/main/some/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ export default useRouteGuards(
beforeRouteUpdate(to, from) {
console.log('HomeMainSomeIndex beforeRouteUpdate', this, to, from);
},
afterRouteEnter(to, from) {
console.log('HomeMainSomeIndex afterRouteEnter', this, to, from);
},
afterRouteLeave(to, from) {
console.log('HomeMainSomeIndex afterRouteLeave', this, to, from);
},
Expand Down
4 changes: 3 additions & 1 deletion demo/src/views/router/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import ReactViewRouter from 'react-view-router';
import ReactViewRouter, { createRouterLink } from 'react-view-router';

const router = new ReactViewRouter();

export const RouterLink = createRouterLink(router);

export default router;
5 changes: 5 additions & 0 deletions drawer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "react-view-router-drawer",
"main": "src/index.js",
"module": "esm/index.js"
}
Loading

0 comments on commit a8d4165

Please sign in to comment.