fix: remove `auth` field, need `next()` for all routes

This commit is contained in:
syy11cn 2021-10-23 00:27:58 +08:00
parent 4115636118
commit 6bd9994084
3 changed files with 23 additions and 39 deletions

View File

@ -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"

View File

@ -18,7 +18,7 @@ const RouterView: FunctionComponent<RouterViewProps> = ({
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,8 +32,6 @@ const RouterView: FunctionComponent<RouterViewProps> = ({
return (
<Switch>
{routes.map((route, index) => {
// If auth needed.
if (route.auth) {
// If `next()` called.
if (agreeToGo) {
// Need to redirect.
@ -48,6 +46,7 @@ const RouterView: FunctionComponent<RouterViewProps> = ({
render={(props) => (
<route.component
{...props}
// Pass routes of route obj down.
routes={route.routes}
></route.component>
)}
@ -55,21 +54,6 @@ const RouterView: FunctionComponent<RouterViewProps> = ({
);
}
}
} else {
// No need for auth.
return (
<Route
key={index}
path={route.path}
render={(props) => (
<route.component
{...props}
routes={route.routes}
></route.component>
)}
></Route>
);
}
})}
</Switch>
);

View File

@ -3,7 +3,6 @@ import * as React from 'react';
interface routeType {
path: string;
component: React.ComponentType<any>;
auth?: boolean;
exact?: boolean;
routes?: Array<routeType> | undefined;
}