fix: remove `auth` field, need `next()` for all routes
This commit is contained in:
parent
4115636118
commit
6bd9994084
|
@ -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"
|
||||
|
|
|
@ -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,43 +32,27 @@ const RouterView: FunctionComponent<RouterViewProps> = ({
|
|||
return (
|
||||
<Switch>
|
||||
{routes.map((route, index) => {
|
||||
// If auth needed.
|
||||
if (route.auth) {
|
||||
// If `next()` called.
|
||||
if (agreeToGo) {
|
||||
// Need to redirect.
|
||||
if (redirectPath) {
|
||||
return <Redirect key={index} to={redirectPath} />;
|
||||
} else {
|
||||
// OK to render.
|
||||
return (
|
||||
<Route
|
||||
key={index}
|
||||
path={route.path}
|
||||
render={(props) => (
|
||||
<route.component
|
||||
{...props}
|
||||
routes={route.routes}
|
||||
></route.component>
|
||||
)}
|
||||
></Route>
|
||||
);
|
||||
}
|
||||
// If `next()` called.
|
||||
if (agreeToGo) {
|
||||
// Need to redirect.
|
||||
if (redirectPath) {
|
||||
return <Redirect key={index} to={redirectPath} />;
|
||||
} else {
|
||||
// OK to render.
|
||||
return (
|
||||
<Route
|
||||
key={index}
|
||||
path={route.path}
|
||||
render={(props) => (
|
||||
<route.component
|
||||
{...props}
|
||||
// Pass routes of route obj down.
|
||||
routes={route.routes}
|
||||
></route.component>
|
||||
)}
|
||||
></Route>
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// No need for auth.
|
||||
return (
|
||||
<Route
|
||||
key={index}
|
||||
path={route.path}
|
||||
render={(props) => (
|
||||
<route.component
|
||||
{...props}
|
||||
routes={route.routes}
|
||||
></route.component>
|
||||
)}
|
||||
></Route>
|
||||
);
|
||||
}
|
||||
})}
|
||||
</Switch>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue