-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathget-router-initial-component.js
More file actions
45 lines (42 loc) · 1.38 KB
/
get-router-initial-component.js
File metadata and controls
45 lines (42 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { getComponentId } from './utils.js';
export const getRouterInitialComponent = (router, initialComponent) => {
let initialComponentData;
const { initialUrl } = router.getInitialUrl();
const initialRoute = router.findMatchingRoute(initialUrl);
let routeProps = router.propsHistory[router.propsHistory.length - 1];
// Store route props first, if not present, fallback to route options
if (!routeProps) {
if (initialRoute && initialRoute.route && initialRoute.route.options) {
routeProps = { ...initialRoute.route.options.props };
router.propsHistory.push(routeProps);
}
}
const isMasterRoute = (route) => {
if (route.master === true) return true;
if (typeof route.master === 'function') return route.master(router.app);
return false;
};
if (
initialRoute &&
initialRoute.route &&
(initialRoute.route.component || initialRoute.route.asyncComponent) &&
!isMasterRoute(initialRoute.route)
) {
initialComponentData = {
component: initialRoute.route.component || initialRoute.route.asyncComponent,
initialComponent,
id: getComponentId(),
isAsync: !!initialRoute.route.asyncComponent,
props: {
f7route: initialRoute,
f7router: router,
...routeProps,
...initialRoute.params,
},
};
}
return {
initialPage: initialComponentData,
initialRoute,
};
};