Skip to content

Commit bc192dc

Browse files
authored
Merge pull request #74 from kne-union/linzp
修改example路由跳转search丢失的bug
2 parents 2440340 + 121e43b commit bc192dc

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kne/modules-dev",
3-
"version": "2.0.23",
3+
"version": "2.0.24",
44
"description": "用于辅助在项目内启动一个规范化组件开发的环境",
55
"publishConfig": {
66
"source": "src/index.js",

src/Example.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
import React from 'react';
2-
import {useParams, Navigate} from "react-router-dom";
2+
import {useParams, Navigate, useSearchParams} from "react-router-dom";
33
import ExamplePage from './ExamplePage';
44
import ensureSlash from '@kne/ensure-slash';
55
import Fetch from '@kne/react-fetch';
66

77
const Example = ({baseUrl, readme, pageProps}) => {
88
const {id: current} = useParams();
9+
const [searchParams] = useSearchParams();
10+
const searchString = searchParams.size > 0 ? '?' + searchParams.toString() : '';
911
const data = readme[current];
1012

11-
if (!readme[current]) {
12-
return <Navigate to={`${ensureSlash(baseUrl, true)}${Object.keys(readme)[0]}`} replace/>
13+
if (!(current && readme[current])) {
14+
return <Navigate to={`${ensureSlash(baseUrl, true)}${Object.keys(readme)[0]}${searchString}`} replace/>
1315
}
1416

1517
const renderExamplePage = ({data}) => <ExamplePage pageProps={pageProps} data={data} current={current}
1618
items={Object.keys(readme).map((name) => {
1719
return {
1820
label: name,
1921
key: name,
20-
path: `${ensureSlash(baseUrl, true)}` + name
22+
path: `${ensureSlash(baseUrl, true)}` + name + searchString
2123
};
2224
})}/>
2325

0 commit comments

Comments
 (0)