fix: change type of next function

This commit is contained in:
syy11cn 2021-10-29 17:11:54 +08:00
parent d4cd576586
commit 161fc9a87f
3 changed files with 9 additions and 4 deletions

2
dist/index.js vendored
View File

@ -1 +1 @@
import{jsx}from"react/jsx-runtime";import{useLocation,Switch,Route,Redirect}from"react-router-dom";var __assign=function(){return(__assign=Object.assign||function(t){for(var r,e=1,o=arguments.length;e<o;e++)for(var n in r=arguments[e])Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n]);return t}).apply(this,arguments)},RouterView=function(t){var r=t.routes,e=t.onEnter,t=useLocation().pathname,o="",n=!0;return e(t,function(t){n=!0,t&&(o=t)}),jsx(Switch,{children:r.map(function(r,t){return r.auth?n?o?jsx(Redirect,{to:o},t):jsx(Route,{path:r.path,render:function(t){return jsx(r.component,__assign({},t,{routes:r.routes}),void 0)}},t):void 0:jsx(Route,{path:r.path,render:function(t){return jsx(r.component,__assign({},t,{routes:r.routes}),void 0)}},t)})},void 0)};export{RouterView};
import{jsx}from"react/jsx-runtime";import{useLocation,Switch,Route,Redirect}from"react-router-dom";var __assign=function(){return(__assign=Object.assign||function(t){for(var r,e=1,o=arguments.length;e<o;e++)for(var n in r=arguments[e])Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n]);return t}).apply(this,arguments)},RouterView=function(t){var r=t.routes,e=t.onEnter,t=useLocation().pathname,o="",n=!0;return e(t,function(t){n=!0,t&&(o=t)}),jsx(Switch,{children:r.map(function(r,t){if(n)return o?jsx(Redirect,{to:o},t):jsx(Route,{path:r.path,exact:r.exact,render:function(t){return jsx(r.component,__assign({},t,{routes:r.routes}),void 0)}},t)})},void 0)};export{RouterView};

View File

@ -4,14 +4,19 @@ import { FunctionComponent } from 'react';
interface routeType {
path: string;
component: React.ComponentType<any>;
auth?: boolean;
exact?: boolean;
routes?: Array<routeType> | undefined;
}
interface RouterViewProps {
routes: Array<routeType>;
onEnter: (to: string, next: Function) => void;
/**
* Require a function to call before routing.
* @param to Pathname of user's destination.
* @param next Function to allow rendering.
* @usage Read more at [github](https://github.com/syy11cn/config-router/blob/main/README.md).
*/
onEnter: (to: string, next: (path?: string) => void) => void;
}
declare const RouterView: FunctionComponent<RouterViewProps>;

View File

@ -10,7 +10,7 @@ interface RouterViewProps {
* @param next Function to allow rendering.
* @usage Read more at [github](https://github.com/syy11cn/config-router/blob/main/README.md).
*/
onEnter: (to: string, next: Function) => void;
onEnter: (to: string, next: (path?: string) => void) => void;
}
const RouterView: FunctionComponent<RouterViewProps> = ({