location.query 改成从 rootRender 获取

This commit is contained in:
liaoxuezhi 2019-06-10 21:08:13 +08:00
parent 0095841120
commit 4669d5fb0a
2 changed files with 36 additions and 24 deletions

View File

@ -1,5 +1,5 @@
import * as React from "react";
import * as PropTypes from 'prop-types';
import * as qs from 'qs';
import {
RendererStore,
IRendererStore,
@ -277,10 +277,21 @@ export class RootRenderer extends React.Component<RootRendererProps> {
rootStore,
env,
pathPrefix,
location,
data,
...rest
} = this.props;
const theme = env.theme;
const query = location && location.query
|| location && location.search && qs.parse(location.search.substring(1))
|| window.location.search && qs.parse(window.location.search.substring(1));
const finalData = query ? {
...data,
...query,
query
} : data;
return (
<RootStoreContext.Provider value={rootStore}>
@ -290,6 +301,7 @@ export class RootRenderer extends React.Component<RootRendererProps> {
...(schema as Schema)
} : schema, {
...rest,
data: finalData,
env,
classnames: theme.classnames,
classPrefix: theme.classPrefix

View File

@ -89,21 +89,21 @@ export default class Page extends React.Component<PageProps> {
'initInterval',
]);
if (location && location.search) {
const query = location.query || qs.parse(location.search.substring(1));
// if (location && location.search) {
// const query = location.query || qs.parse(location.search.substring(1));
store.reInitData({
...query,
query: query,
});
} else if (!location && window.location.search) {
const query = qs.parse(window.location.search.substring(1));
// store.reInitData({
// ...query,
// query: query,
// });
// } else if (!location && window.location.search) {
// const query = qs.parse(window.location.search.substring(1));
store.reInitData({
...query,
query: query,
});
}
// store.reInitData({
// ...query,
// query: query,
// });
// }
}
componentDidMount() {
@ -129,16 +129,16 @@ export default class Page extends React.Component<PageProps> {
const props = this.props;
const store = props.store;
if (nextProps.location && (!props.location || props.location.search !== nextProps.location.search)) {
const query =
nextProps.location.query ||
(nextProps.location.search && qs.parse(nextProps.location.search.substring(1))) ||
{};
store.updateData({
...query,
query: query,
});
}
// if (nextProps.location && (!props.location || props.location.search !== nextProps.location.search)) {
// const query =
// nextProps.location.query ||
// (nextProps.location.search && qs.parse(nextProps.location.search.substring(1))) ||
// {};
// store.updateData({
// ...query,
// query: query,
// });
// }
}
componentDidUpdate(prevProps: PageProps) {