-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(demos): support listen cwf redirect query params
- Loading branch information
Showing
6 changed files
with
169 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,61 @@ | ||
import { Component } from 'react'; | ||
import { | ||
type FC, | ||
type PropsWithChildren, | ||
useLayoutEffect, | ||
useRef, | ||
useCallback, | ||
} from 'react'; | ||
import { useRouter, useEnv, useApp } from 'taro-hooks'; | ||
import { ENV_TYPE } from '@tarojs/taro'; | ||
import './app.css'; | ||
|
||
class App extends Component { | ||
componentDidMount() {} | ||
const App: FC<PropsWithChildren> = ({ children }) => { | ||
const [pageInfo, { navigate }] = useRouter(); | ||
const { setGlobalData } = useApp(); | ||
const env = useEnv(); | ||
const checkParams = useRef<typeof pageInfo.params>(); | ||
|
||
componentDidShow() {} | ||
const handleCheckNavigate = useCallback(() => { | ||
const checkQueryField = ['type', 'hook', 'sub', 'function']; | ||
const pageParams = pageInfo.params; | ||
// 包含前两个即可 | ||
if (checkQueryField.slice(0, 2).every((v) => pageParams[v])) { | ||
// 对比两个是否一致 | ||
const isEqual = Object.keys(pageParams).reduce((result, key) => { | ||
if (!result) { | ||
return result; | ||
} | ||
|
||
componentDidHide() {} | ||
return pageParams[key] === checkParams.current?.[key]; | ||
}, true); | ||
|
||
componentDidCatchError() {} | ||
if (!isEqual) { | ||
const path = checkQueryField.reduce( | ||
(forwardPath, key) => [forwardPath, `/${pageParams[key]}`].join(''), | ||
'/pages', | ||
); | ||
checkParams.current = pageParams; | ||
navigate(path); | ||
} | ||
} | ||
}, [pageInfo]); | ||
|
||
globalData = { | ||
framework: 'React', | ||
package: 'taro-hooks next', | ||
basic: 'taro', | ||
}; | ||
useLayoutEffect(() => { | ||
// @ts-ignore | ||
if (env === ENV_TYPE['WEB'] && CF !== '0') { | ||
handleCheckNavigate(); | ||
} | ||
}, [pageInfo.params]); | ||
|
||
// this.props.children 是将要会渲染的页面 | ||
render() { | ||
return this.props.children; | ||
} | ||
} | ||
useLayoutEffect(() => { | ||
Object.entries({ | ||
framework: 'React', | ||
package: 'taro-hooks next', | ||
basic: 'taro', | ||
}).forEach((params) => setGlobalData(...params)); | ||
}, []); | ||
|
||
return children; | ||
}; | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters