UNPKG

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