From 6bd9994084397eb5c07a2ab6a7d2380344f6b472 Mon Sep 17 00:00:00 2001 From: syy11cn Date: Sat, 23 Oct 2021 00:27:58 +0800 Subject: [PATCH] fix: remove `auth` field, need `next()` for all routes --- package.json | 3 ++- src/index.tsx | 58 ++++++++++++++++---------------------------- typings/routeType.ts | 1 - 3 files changed, 23 insertions(+), 39 deletions(-) diff --git a/package.json b/package.json index b941bf9..7628bba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "@syy11cn/config-router", - "version": "1.0.1", + "version": "1.0.3", + "description": "A route rendering and route guarding lib.", "author": { "name": "Yiyang Sun", "email": "syy11cn@outlook.com" diff --git a/src/index.tsx b/src/index.tsx index c48cbbe..5494860 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -18,7 +18,7 @@ const RouterView: FunctionComponent = ({ let redirectPath: string = ''; let agreeToGo = true; - // Change state of `redirectPath` and `agreeToGo` + // Change state of `redirectPath` and `agreeToGo`. function next(path?: string) { agreeToGo = true; if (path) { @@ -32,43 +32,27 @@ const RouterView: FunctionComponent = ({ return ( {routes.map((route, index) => { - // If auth needed. - if (route.auth) { - // If `next()` called. - if (agreeToGo) { - // Need to redirect. - if (redirectPath) { - return ; - } else { - // OK to render. - return ( - ( - - )} - > - ); - } + // If `next()` called. + if (agreeToGo) { + // Need to redirect. + if (redirectPath) { + return ; + } else { + // OK to render. + return ( + ( + + )} + > + ); } - } else { - // No need for auth. - return ( - ( - - )} - > - ); } })} diff --git a/typings/routeType.ts b/typings/routeType.ts index e96171b..5df48eb 100644 --- a/typings/routeType.ts +++ b/typings/routeType.ts @@ -3,7 +3,6 @@ import * as React from 'react'; interface routeType { path: string; component: React.ComponentType; - auth?: boolean; exact?: boolean; routes?: Array | undefined; }