fix: remove unused code
This commit is contained in:
parent
c4dfe038c5
commit
9e2169a980
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) [2021] [Yiyang Sun]
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
|
@ -0,0 +1,38 @@
|
||||||
|
import { jsx as _jsx } from "react/jsx-runtime";
|
||||||
|
import { Switch, useLocation, useRouteMatch, Route, Redirect, } from 'react-router-dom';
|
||||||
|
const RouterView = ({ routes, onEnter, }) => {
|
||||||
|
const { pathname } = useLocation();
|
||||||
|
const match = useRouteMatch();
|
||||||
|
console.log('当前页面路径:' + pathname);
|
||||||
|
console.log('路径匹配', match);
|
||||||
|
let redirectPath = '';
|
||||||
|
let agreeToGo = true;
|
||||||
|
function next(path) {
|
||||||
|
agreeToGo = true;
|
||||||
|
if (path) {
|
||||||
|
redirectPath = path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onEnter(pathname, next);
|
||||||
|
return (_jsx(Switch, { children: routes.map((route, index) => {
|
||||||
|
// If auth needed.
|
||||||
|
if (route.auth) {
|
||||||
|
// If `next()` called.
|
||||||
|
if (agreeToGo) {
|
||||||
|
// Need to redirect.
|
||||||
|
if (redirectPath) {
|
||||||
|
return _jsx(Redirect, { to: redirectPath }, index);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// OK to render.
|
||||||
|
return (_jsx(Route, { path: route.path, render: (props) => (_jsx(route.component, Object.assign({}, props, { routes: route.routes }), void 0)) }, index));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// No need for auth.
|
||||||
|
return (_jsx(Route, { path: route.path, render: (props) => (_jsx(route.component, Object.assign({}, props, { routes: route.routes }), void 0)) }, index));
|
||||||
|
}
|
||||||
|
}) }, void 0));
|
||||||
|
};
|
||||||
|
export { RouterView };
|
|
@ -0,0 +1 @@
|
||||||
|
export {};
|
10
package.json
10
package.json
|
@ -1,8 +1,16 @@
|
||||||
{
|
{
|
||||||
"name": "config-router",
|
"name": "config-router",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"main": "index.js",
|
"author": {
|
||||||
|
"name": "Yiyang Sun",
|
||||||
|
"email": "syy11cn@outlook.com"
|
||||||
|
},
|
||||||
|
"main": "dist/src/index.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git@github.com:syy11cn/config-router.git"
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"react-router-dom": "^5.3.0"
|
"react-router-dom": "^5.3.0"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,11 +1,5 @@
|
||||||
import { FunctionComponent } from 'react';
|
import { FunctionComponent } from 'react';
|
||||||
import {
|
import { Switch, useLocation, Route, Redirect } from 'react-router-dom';
|
||||||
Switch,
|
|
||||||
useLocation,
|
|
||||||
useRouteMatch,
|
|
||||||
Route,
|
|
||||||
Redirect,
|
|
||||||
} from 'react-router-dom';
|
|
||||||
import routeType from '../typings/routeType';
|
import routeType from '../typings/routeType';
|
||||||
|
|
||||||
interface RouterViewProps {
|
interface RouterViewProps {
|
||||||
|
@ -17,14 +11,14 @@ const RouterView: FunctionComponent<RouterViewProps> = ({
|
||||||
routes,
|
routes,
|
||||||
onEnter,
|
onEnter,
|
||||||
}) => {
|
}) => {
|
||||||
|
// Pathname of current page.
|
||||||
const { pathname } = useLocation();
|
const { pathname } = useLocation();
|
||||||
const match = useRouteMatch();
|
|
||||||
console.log('当前页面路径:' + pathname);
|
|
||||||
console.log('路径匹配', match);
|
|
||||||
|
|
||||||
|
// No redirect and no agree to go by default.
|
||||||
let redirectPath: string = '';
|
let redirectPath: string = '';
|
||||||
let agreeToGo = true;
|
let agreeToGo = true;
|
||||||
|
|
||||||
|
// Change state of `redirectPath` and `agreeToGo`
|
||||||
function next(path?: string) {
|
function next(path?: string) {
|
||||||
agreeToGo = true;
|
agreeToGo = true;
|
||||||
if (path) {
|
if (path) {
|
||||||
|
@ -32,6 +26,7 @@ const RouterView: FunctionComponent<RouterViewProps> = ({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use hook.
|
||||||
onEnter(pathname, next);
|
onEnter(pathname, next);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -1,20 +1,21 @@
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ESNext",
|
"target": "ESNext",
|
||||||
"useDefineForClassFields": true,
|
// "useDefineForClassFields": true,
|
||||||
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
// "lib": ["DOM", "DOM.Iterable", "ESNext"],
|
||||||
"allowJs": false,
|
// "allowJs": false,
|
||||||
"skipLibCheck": false,
|
// "skipLibCheck": false,
|
||||||
"esModuleInterop": false,
|
// "esModuleInterop": false,
|
||||||
"allowSyntheticDefaultImports": true,
|
// "allowSyntheticDefaultImports": true,
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"forceConsistentCasingInFileNames": true,
|
// "forceConsistentCasingInFileNames": true,
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"moduleResolution": "Node",
|
"moduleResolution": "Node",
|
||||||
"resolveJsonModule": true,
|
// "resolveJsonModule": true,
|
||||||
"isolatedModules": true,
|
// "isolatedModules": true,
|
||||||
"noEmit": true,
|
// "noEmit": true,
|
||||||
"jsx": "react-jsx"
|
"jsx": "react-jsx",
|
||||||
|
"outDir": "dist"
|
||||||
},
|
},
|
||||||
"include": ["./src/**/*"]
|
"include": ["src/**/*"]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
interface routeType {
|
interface routeType {
|
||||||
path: string;
|
path: string;
|
||||||
|
|
Loading…
Reference in New Issue