fix: router rerender

This commit is contained in:
rorya.lyj 2020-08-18 10:24:51 +08:00
parent 9baba75ca1
commit d886abc48d
3 changed files with 35 additions and 21 deletions

View File

@ -130,27 +130,27 @@
}, },
{ {
"prototypeViewsUrl": null, "prototypeViewsUrl": null,
"packageName": "@ali/vc-deep-mobile-yidaplus",
"version": "1.0.4",
"prototypeConfigsUrl": [
"https://g.alicdn.com/legao-comp/web_bundle_0724/@ali/vc-deep-mobile-yidaplus/1.0.4/proto.23e380d.css",
"https://g.alicdn.com/legao-comp/web_bundle_0724/@ali/vc-deep-mobile-yidaplus/1.0.4/proto.4d55c72.js"
],
"prototypeUrls": { "prototypeUrls": {
"default": [ "default": [
"https://g.alicdn.com/legao-comp/web_bundle_0724/@ali/vc-deep-mobile/2.0.1-beta.25/proto.2f23cdf.css", "https://g.alicdn.com/legao-comp/web_bundle_0724/@ali/vc-deep-mobile-yidaplus/1.0.4/proto.23e380d.css",
"https://g.alicdn.com/legao-comp/web_bundle_0724/@ali/vc-deep-mobile/2.0.1-beta.25/proto.9a739a7.js" "https://g.alicdn.com/legao-comp/web_bundle_0724/@ali/vc-deep-mobile-yidaplus/1.0.4/proto.4d55c72.js"
] ]
}, },
"prototypeConfigsUrl": [ "library": "AliVcDeepMobileYidaplus",
"https://g.alicdn.com/legao-comp/web_bundle_0724/@ali/vc-deep-mobile/2.0.1-beta.25/proto.2f23cdf.css", "urls": [
"https://g.alicdn.com/legao-comp/web_bundle_0724/@ali/vc-deep-mobile/2.0.1-beta.25/proto.9a739a7.js" "https://g.alicdn.com/legao-comp/web_bundle_0724/@ali/vc-deep-mobile-yidaplus/1.0.4/view.574f830.css",
"https://g.alicdn.com/legao-comp/web_bundle_0724/@ali/vc-deep-mobile-yidaplus/1.0.4/view.fe356f3.js",
"https://g.alicdn.com/legao-comp/web_bundle_0724/@ali/vc-deep-mobile-yidaplus/1.0.4/view.mobile.574f830.css",
"https://g.alicdn.com/legao-comp/web_bundle_0724/@ali/vc-deep-mobile-yidaplus/1.0.4/view.mobile.f993078.js"
], ],
"alias": "", "alias": "",
"urls": [ "components": null
"https://g.alicdn.com/legao-comp/web_bundle_0724/@ali/vc-deep-mobile/2.0.1-beta.25/view.d6d0d1f.css",
"https://g.alicdn.com/legao-comp/web_bundle_0724/@ali/vc-deep-mobile/2.0.1-beta.25/view.14bb8e8.js",
"https://g.alicdn.com/legao-comp/web_bundle_0724/@ali/vc-deep-mobile/2.0.1-beta.25/view.mobile. d6d0d1f.css",
"https://g.alicdn.com/legao-comp/web_bundle_0724/@ali/vc-deep-mobile/2.0.1-beta.25/view.mobile.fe36565.js"
],
"library": "AliVcDeepMobile",
"components": null,
"packageName": "@ali/vc-deep-mobile",
"version": "2.0.1-beta.25"
}, },
{ {
"prototypeViewsUrl": null, "prototypeViewsUrl": null,

View File

@ -208,6 +208,8 @@ function getInitialComponent(routerConfig) {
return InitialComponent; return InitialComponent;
} }
let unlisten = null;
let handleId = null;
export function useRouter(routerConfig) { export function useRouter(routerConfig) {
const [component, setComponent] = useState(getInitialComponent(routerConfig)); const [component, setComponent] = useState(getInitialComponent(routerConfig));
@ -218,29 +220,41 @@ export function useRouter(routerConfig) {
} }
useLayoutEffect(() => { useLayoutEffect(() => {
if (_initialized) return; if (unlisten) {
_initialized = true; unlisten();
unlisten = null;
}
if (handleId) {
router.removeHandle(handleId);
handleId = null;
}
const history = _routerConfig.history; const history = _routerConfig.history;
const routes = _routerConfig.routes; const routes = _routerConfig.routes;
router.root = Array.isArray(routes) ? { routes } : routes; router.root = Array.isArray(routes) ? { routes } : routes;
const handleId = router.addHandle((component) => { handleId = router.addHandle((component) => {
setComponent(component); setComponent(component);
}); });
// Init path match // Init path match
if (!_routerConfig.InitialComponent) { if (_initialized || !_routerConfig.InitialComponent) {
matchLocation(history.location); matchLocation(history.location);
} }
const unlisten = history.listen(({ location }) => { unlisten = history.listen(({ location }) => {
matchLocation(location); matchLocation(location);
}); });
_initialized = true;
return () => { return () => {
router.removeHandle(handleId); router.removeHandle(handleId);
handleId = null;
unlisten(); unlisten();
unlisten = null;
}; };
}, []); }, []);

View File

@ -237,7 +237,7 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
constructor() { constructor() {
this.dispose = host.connect(this, () => { this.dispose = host.connect(this, () => {
// sync layout config // sync layout config
debugger; // debugger;
this._layout = host.project.get('config').layout; this._layout = host.project.get('config').layout;
// todo: split with others, not all should recompute // todo: split with others, not all should recompute