我有2个不同的模块,一个是常见的UI模块,其中有sso-Button组件,另一个是SSO模块,其中有initiatesso组件。
sso-button组件中有一个按钮,如果单击该按钮,则应将其重定向到initialsso组件。
我尝试了以下代码。
模块:CommonUI模块 Sso-button.component.html:
<button class="logo-button" (click)="alert()" style="position:absolute;">
</button>
Sso-button.component.ts:
public alert() {
alert("");
this.router.navigateByUrl(`initiatesso`);
}
模块:SSO模块
sso.module.ts:
export const ssoRoutes: Routes = [
{
path: 'initiatesso',
component: InitiatessoComponent
}
];
@NgModule({
imports: [
RouterModule.forChild(ssoRoutes),
],
declarations: [InitiatessoComponent],
exports: [InitiatessoComponent]
})
export class SsoModule { }
initiatesso.component.html
initiatesso works!
initiatesso.component.ts
export class InitiatessoComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
但是在按钮上单击“我无法重定向到initialsso”页面,不确定我要去哪里。请帮忙。
答案 0 :(得分:1)
对于UI模块,您需要导入SsoModule
所以您的代码看起来像这样
Bundle b = getIntent().getExtras();
int[][] list_array = (int[][])b.getSerializable("array");
然后在您的主路由中,需要添加sso路由
@NgModule({
bootstrap: [AppComponent],
imports: [
SsoModule,
RouterModule.forRoot(mainRoutes)
]
然后将您的SSOModule代码更改为此
export const mainRoutes: Routes = [
{
path: 'initiatesso',
component: InitiatessoComponent
}
];
RouterModule.forChild在您具有模块的子路由时使用,因此您只需在Route模块中为SSO模块定义子路由,例如
export const ssoRoutes: Routes = [
{
path: '',
component: InitiatessoComponent
}
];
@NgModule({
imports: [
RouterModule.forChild(ssoRoutes),
],
declarations: [InitiatessoComponent],
exports: [InitiatessoComponent]
})
export class SsoModule { }
module / abc /
所以现在您可以使用
export const ssoRoutes: Routes = [
{
path: '',
component: InitiatessoComponent
},
{
path: 'abc',
component: InitiatessoABCComponent
}
];
如果需要帮助,请告诉我