背景:react umi框架,约定式路由,history.type = hash。
场景:空白的浏览器路径输入 -- localhost:8000/#/font 通过font页面里逻辑跳转到http://localhost:8000/#/home localhost:8000/#/home 页面 ,然后在home页面点击history.goBack()的时候,奇奇怪怪的问题 出现了。。 奶奶个腿居然给我退到了空白页面。。我要的是返回font页面呀!
20220414103257
↓↓↓ font页面 ↓↓↓
import React from 'react';
import { history } from 'umi';
import styles from './FontPage.less';
const FontPage = () => {
const onClick = () => {
history.push('/home');
};
onClick();
return <div className={`${styles.root}`}>This is FontPage.</div>;
};
export default FontPage;
↓↓↓ home页面 ↓↓↓
import React from 'react';
import styles from './HomePage.less';
import { history } from 'umi';
const HomePage = () => {
return (
<div className={`${styles.root}`}>
This is HomePage.
<h1
onClick={() => {
history.goBack();
}}
>
goBack
</h1>
</div>
);
};
export default HomePage;
最终解决:
font页面跳转到home页面加个 延时器。
完美解决,但是我不李姐。。
↓↓↓ font页面 ↓↓↓
import React from 'react';
import { history } from 'umi';
import styles from './FontPage.less';
const FontPage = () => {
const onClick = () => {
setTimeout(() => {
history.push('/home');
}, 1000);
};
onClick();
return <div className={`${styles.root}`}>This is FontPage.</div>;
};
export default FontPage;