Ionic 4 路由不工作 url 更改但视图未出现
Ionic 4 routing not working the url changes but view doesnt appear
我正在开发一个 Ionic 4 应用程序,我有两个页面的身份验证和注册,我在 "app-routing.module" 中添加了我的路由,我将我的身份验证组件设置为根组件,所以当我点击视图路线发生变化,注册视图未出现:
App-routing.module
const routes: Routes = [
{ path: '', redirectTo: 'auth', pathMatch: 'full' },
{ path: 'auth', component: AuthenticationComponent },
{ path: 'registerFirst', component: RegistrationComponent},
];
...
这是身份验证视图中的按钮
<ion-button expand="full" color="medium" [routerLink]="['/registerFirst']">CREATE AN
ACCOUNT</ion-button>
像这样更改路由:
{ path: '', redirectTo: 'registration', pathMatch: 'full' },
{
path: 'registration',
loadChildren: 'yourpath/registration.module#RegistrationPageModule'
},
...
并且您必须将此代码添加到 registration.module.ts
:
import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [
{
path: '',
component: RegistrationPage
}
];
@NgModule({
imports: [
...
RouterModule.forChild(routes)
],
.....
})
我希望它能彻底发挥作用
我遇到了完全相同的问题,结果证明解决方案有点出乎意料:
我从 global.scss 中注释掉了这一行:@import "~@ionic/angular/css/core.css";
,取消注释它修复了渲染问题。
很多人遇到这个问题的原因是因为从 Ionic 3 迁移到 Ionic 4 有点令人困惑,注释掉一些东西只是将它们一个一个地添加回去是了解发生了什么的好方法,不幸的是,如果您最终评论了错误的行,则可能会出现此类问题。
我正在开发一个 Ionic 4 应用程序,我有两个页面的身份验证和注册,我在 "app-routing.module" 中添加了我的路由,我将我的身份验证组件设置为根组件,所以当我点击视图路线发生变化,注册视图未出现:
App-routing.module
const routes: Routes = [
{ path: '', redirectTo: 'auth', pathMatch: 'full' },
{ path: 'auth', component: AuthenticationComponent },
{ path: 'registerFirst', component: RegistrationComponent},
];
...
这是身份验证视图中的按钮
<ion-button expand="full" color="medium" [routerLink]="['/registerFirst']">CREATE AN
ACCOUNT</ion-button>
像这样更改路由:
{ path: '', redirectTo: 'registration', pathMatch: 'full' },
{
path: 'registration',
loadChildren: 'yourpath/registration.module#RegistrationPageModule'
},
...
并且您必须将此代码添加到 registration.module.ts
:
import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [
{
path: '',
component: RegistrationPage
}
];
@NgModule({
imports: [
...
RouterModule.forChild(routes)
],
.....
})
我希望它能彻底发挥作用
我遇到了完全相同的问题,结果证明解决方案有点出乎意料:
我从 global.scss 中注释掉了这一行:@import "~@ionic/angular/css/core.css";
,取消注释它修复了渲染问题。
很多人遇到这个问题的原因是因为从 Ionic 3 迁移到 Ionic 4 有点令人困惑,注释掉一些东西只是将它们一个一个地添加回去是了解发生了什么的好方法,不幸的是,如果您最终评论了错误的行,则可能会出现此类问题。