我有一个Angular 2应用程序,并希望以true/false boolean标志的模式通过,可以通过这样的应用程序来读取:
http://www.outapp.com/<appbase>/<mode>/<routes>/<child-routes>/<etc>
@Component({
selector: 'my-app', // <my-app></my-app>
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
standAloneMode: boolean = true;
// private viewContainerRef: ViewContainerRef;
constructor(private router: Router, private api: ApiService, private loader: LoaderService) {
standAloneMode = Router.SOMETHINGFROMTHEPARAMS;
}
如何在不打扰配置的路由的情况下传递标志?
您可以在 route.ts
中使用以下路径参数:
const routes; Routes = [
...
{path: '/:mode/routes/child-routes/etc', component: YourComponent}
....
]
然后在您的组件中,以下读取模式参数:
ngOnInit() {
this.route.params.subscribe(param=> {
if (param['mode'] !== undefined) {
this.mode= param['mode'];
etc.
}
});
etc.
}