H5.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { WebView } from "@tarojs/components";
  2. import Taro from "@tarojs/taro";
  3. import { useRouter } from "@tarojs/taro";
  4. import { useEffect } from "react";
  5. import { useTranslation } from "react-i18next";
  6. let useRoute,useNavigation;
  7. if (process.env.TARO_ENV == 'rn') {
  8. useRoute = require("@react-navigation/native").useRoute
  9. useNavigation = require("@react-navigation/native").useNavigation
  10. // useNavigation = require("@react-navigation/native").useNavigation
  11. }
  12. export default function Page() {
  13. const { t } = useTranslation()
  14. let navigation;
  15. if (useNavigation) {
  16. navigation = useNavigation()
  17. }
  18. let router;
  19. if (process.env.TARO_ENV == 'weapp') {
  20. router = useRouter();
  21. }
  22. else {
  23. router = useRoute()
  24. }
  25. useEffect(() => {
  26. if (process.env.TARO_ENV == 'rn') {
  27. navigation.setOptions({ title: router.params.title ?? '' });
  28. }
  29. else {
  30. Taro.setNavigationBarTitle({
  31. title: router.params.title ?? ''
  32. // title:t('feature.track_time_duration.follow_wx_pub.title')
  33. })
  34. }
  35. }, [])
  36. return (
  37. <WebView style={{ display: 'flex', flex: 1 }} src={router.params.url as string} />
  38. )
  39. }