1 | import { defineCustomElementTaroTabbar } from '@tarojs/components/dist/components';
|
2 | import { initTabBarApis } from '@tarojs/taro';
|
3 |
|
4 | function initTabbar(config, history) {
|
5 | if (config.tabBar == null || config.tabBar.custom) {
|
6 | return;
|
7 | }
|
8 |
|
9 | defineCustomElementTaroTabbar();
|
10 | const tabbar = document.createElement('taro-tabbar');
|
11 | const homePage = config.entryPagePath || (config.pages ? config.pages[0] : '');
|
12 | tabbar.conf = config.tabBar;
|
13 | tabbar.conf.homePage = history.location.pathname === '/' ? homePage : history.location.pathname;
|
14 | const routerConfig = config.router;
|
15 | tabbar.conf.mode = routerConfig && routerConfig.mode ? routerConfig.mode : 'hash';
|
16 | if (routerConfig.customRoutes) {
|
17 | tabbar.conf.custom = true;
|
18 | tabbar.conf.customRoutes = routerConfig.customRoutes;
|
19 | }
|
20 | else {
|
21 | tabbar.conf.custom = false;
|
22 | tabbar.conf.customRoutes = {};
|
23 | }
|
24 | if (typeof routerConfig.basename !== 'undefined') {
|
25 | tabbar.conf.basename = routerConfig.basename;
|
26 | }
|
27 | const container = document.getElementById('container');
|
28 | container === null || container === void 0 ? void 0 : container.appendChild(tabbar);
|
29 | initTabBarApis(config);
|
30 | }
|
31 |
|
32 | export { initTabbar };
|