我遇到了这个奇怪的问题,我已经启动了一个带有选项卡和角度路由的新应用程序。我添加了一个新的登录页面,登录后,用户被重定向到标签页。问题是重定向后,有时只渲染一个选项卡,有时会渲染两个选项卡。如果我刷新页面或直接转到它,则会显示所有 3 个选项卡。如果我在选项卡页面上启动应用程序,则再次显示所有 3 个选项卡。
应用路由模块:
const routes: Routes = [
{path: 'login', loadChildren: './login/login.module#LoginPageModule'},
{path: 'home', loadChildren: './tabs/tabs.module#TabsPageModule'},
{path: '', redirectTo: '/login', pathMatch: 'full'}];
标签页路由模块:
const routes: Routes = [
{
path: '',
component: TabsPage,
children: [
{
path: 'home',
outlet: 'home',
component: HomePage
},
{
path: 'about',
outlet: 'about',
component: AboutPage
},
{
path: 'contact',
outlet: 'contact',
component: ContactPage
}
]
},
{
path: '',
redirectTo: '/tabs/(home:home)',
pathMatch: 'full'
}];
登录页面:
export class LoginPage implements OnInit {
responseData: any;
userData = {'email': '', 'password': ''};
constructor(public navCtrl: NavController, public apiService: ApiService, public toastCtrl: ToastController) {
}
login() {
this.apiService.login(this.userData).then((result) => {
this.responseData = result;
if (this.responseData.token) {
console.log(this.responseData);
localStorage.setItem('token', this.responseData.token);
this.navCtrl.goRoot('/home');
} else {
console.log('User already exists');
}
}, (err) => {
// Error log
console.log(err);
});
}
ngOnInit() {
}}
有任何想法吗?谢谢!