2019-04-30 11:11:25 +08:00
|
|
|
/**
|
|
|
|
* @file entry of this example.
|
|
|
|
* @author liaoxuezhi@cloud.com
|
|
|
|
*/
|
2020-11-18 11:41:04 +08:00
|
|
|
import './polyfills/index';
|
2022-03-30 12:47:37 +08:00
|
|
|
import React, {useEffect} from 'react';
|
|
|
|
|
|
|
|
import {createRoot} from 'react-dom/client';
|
2019-04-30 11:11:25 +08:00
|
|
|
import App from './components/App';
|
|
|
|
|
2022-03-30 12:47:37 +08:00
|
|
|
function AppWithCallbackAfterRender() {
|
|
|
|
useEffect(() => {
|
2021-11-09 13:46:19 +08:00
|
|
|
// 由于延迟加载导致初始锚点经常不正确
|
|
|
|
// 延迟再设置一下锚点,这个问题暂时没想到其它方法
|
|
|
|
setTimeout(() => {
|
|
|
|
if (location.hash) {
|
|
|
|
const hash = location.hash.split('#')[1];
|
|
|
|
const anchor = document.querySelector(`a[name="${hash}"]`);
|
|
|
|
if (anchor) {
|
|
|
|
anchor.scrollIntoView();
|
|
|
|
}
|
|
|
|
}
|
2021-11-12 12:36:44 +08:00
|
|
|
}, 2000);
|
2021-11-09 13:46:19 +08:00
|
|
|
});
|
2022-03-30 12:47:37 +08:00
|
|
|
|
|
|
|
return <App />;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function bootstrap(mountTo, initalState) {
|
|
|
|
const root = createRoot(mountTo);
|
|
|
|
root.render(<AppWithCallbackAfterRender />);
|
2019-04-30 11:11:25 +08:00
|
|
|
}
|