Skip to content

Commit a89ce0d

Browse files
committed
update to 1.0.9
1 parent 351c05f commit a89ce0d

File tree

8 files changed

+226
-57
lines changed

8 files changed

+226
-57
lines changed

README.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,63 @@ see: [Route Object Properties](https://router.vuejs.org/api/#route-object-proper
263263
- `push``replace``go``back``forward` `redirect`[history navigation methods](https://router.vuejs.org/guide/essentials/navigation.html)
264264
- `parseQuery``stringifyQuery` Provide custom query string parse / stringify functions, can be override by `new ReactViewRouter({ parseQuery: parseQueryMethod, stringifyQuery: stringifyQueryMethod });`
265265

266+
### Export Methods
267+
- `useRouteGuards` route component guards methods:
268+
```javascript
269+
/**
270+
* route component guards methods
271+
* @param {Object} component - route component
272+
* @param {Object} guards - guards methods
273+
* @param {Class} [componentClass] - the route component class, it will be useful when component is High-order components
274+
* @return {RouteComponentGuards} - the route componet that can be regarded as `React.forwardRef`
275+
* /
276+
function useRouteGuards(component, guards = {}, componentClass) {}
277+
```
278+
279+
- `lazyImport` route component lazy load method:
280+
```javascript
281+
/**
282+
* route component lazy load method
283+
* @param {Function} importMethod - webpack lazy import method, For example: () => import('@/components/some-component')
284+
* @return {RouteLazy} - the result only be used with component or components props in route config
285+
* /
286+
function lazyImport(importMethod) {}
287+
```
288+
289+
- `normalizeRoutes` normalize route configs:
290+
```javascript
291+
/**
292+
* normalize route configs
293+
* @param {Array} routes - unnormalized route configs
294+
* @param {Object} [parent] - if provide, routes will be resolved regarded as parert`s children
295+
* @return {Array} - normalized route configs
296+
* /
297+
function normalizeRoutes(routes, parent) {}
298+
```
299+
- `normalizeLocation` normalize location string or object:
300+
```javascript
301+
/**
302+
* normalize location string or object
303+
* @param {Object|string} to - location that need to normalize
304+
* @param {Object} [parent] - if provide, location will be resolved with parert
305+
* @return {Object} - normalized location object: { path: string, pathname: string, search: string, query: Object, ...custom props }
306+
* /
307+
function normalizeLocation(to, parent) {}
308+
```
309+
310+
- `isLocation` determine whether `v` is a location object
311+
```javascript
312+
/**
313+
* determine whether `v` is a location object
314+
* @param {Object} v - the object to be determined
315+
* @return {boolean}
316+
* /
317+
function isLocation(v) {}
318+
```
319+
320+
- `withRouter` just re-export, see: [withRouter](https://reacttraining.com/react-router/web/api/withRouter)
321+
- `matchPath` just re-export, see: [matchPath](https://reacttraining.com/react-router/web/api/matchPath)
322+
266323
## NOTE
267324
1. You sholud config the `Webpack Configuration` with `alias`:
268325
```javascript
@@ -279,7 +336,7 @@ see: [Route Object Properties](https://router.vuejs.org/api/#route-object-proper
279336
```
280337
otherwise, webpack will package both `history` and `history-fix` into the target js file.
281338
282-
2. when route component is `Class Component` (not `Function Component`), the `this` in `afterRouteEnter`, `beforeRouteUpdate`,`beforeRouteLeave`,`afterRouteLeave` Component Guards and `afterEnter`,`beforeUpdate`,`beforeLeave`,`afterLeave` in Route Guards will be the component instance;
339+
2. if route component is `Class Component` (not `Function Component`), then `this` variable in `afterRouteEnter`, `beforeRouteUpdate`,`beforeRouteLeave`,`afterRouteLeave` Component Guards and `afterEnter`,`beforeUpdate`,`beforeLeave`,`afterLeave` in Route Guards will be that component instance;
283340
284341
## License
285342

dist/react-view-router.js

Lines changed: 99 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/react-view-router.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/react-view-router.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-view-router",
3-
"version": "1.0.8",
3+
"version": "1.0.9",
44
"description": "react-view-router",
55
"keywords": [
66
"react-view-router",

src/route-guard.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ export const REACT_LAZY_TYPE = LazyMeth.$$typeof;
88

99
export class RouteCuards {
1010
constructor(guards, isComponentGuards = false) {
11-
this.isComponentGuards = isComponentGuards;
1211
this.beforeEnter = [];
1312
this.beforeUpdate = [];
1413
this.afterEnter = [];
1514
this.beforeLeave = [];
1615
this.afterLeave = [];
16+
17+
Object.defineProperty(this, 'isComponentGuards', { writable: true, configurable: true, value: isComponentGuards });
18+
1719
this.merge(guards || {}, isComponentGuards);
1820
}
1921

@@ -32,14 +34,19 @@ export class RouteCuards {
3234
}
3335
}
3436

35-
export function useRouteGuards(component, guards = {}) {
36-
const ret = {
37-
$$typeof: REACT_FORWARD_REF_TYPE,
38-
render(props, ref) {
39-
return React.createElement(component, { ...props, ref });
40-
}
37+
class RouteComponentGuards {
38+
constructor() {
39+
this.$$typeof = REACT_FORWARD_REF_TYPE;
40+
}
41+
}
42+
43+
export function useRouteGuards(component, guards = {}, componentClass) {
44+
const ret = new RouteComponentGuards();
45+
ret.render = function (props, ref) {
46+
return React.createElement(component, { ...props, ref });
4147
};
4248
Object.defineProperty(ret, '__guards', { value: new RouteCuards(guards, true) });
4349
Object.defineProperty(ret, '__component', { value: component });
50+
Object.defineProperty(ret, '__componentClass', { value: componentClass });
4451
return ret;
4552
}

src/router.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ export default class ReactViewRouter {
218218
...last.match,
219219
query: to.search ? qs.parseQuery(to.search.substr(1)) : {},
220220
path: to.pathname,
221+
hash: to.search,
221222
fullPath: `${to.path}${to.search}`,
222223
matched: matched.map(({ route }, i) => {
223224
let ret = {};

0 commit comments

Comments
 (0)