一些用户通过邀请进入我的Web应用程序。因此他们会有一个看起来像这样的链接:https://example.com/invitaion/12345
其中12345是他们的唯一邀请号码。
当用户单击链接,并且框架在客户端初始化了我的AppComponent时,如何获得使用的URL为“ invitation / *”的事实以及如何获得邀请号?
您将要用于RouteParams
访问该变量,并在Component中使用它。
// let's assume you labeled it as `path : '/invitation/:id'` in your @Route setup.
@Route([
{ path : '/invitation/:id', component : MyComponent }
])
现在在组件本身中:
import { RouteParams } from '@angular/router';
// Now simply get the ID when injecting RouteParams within your constructor
class MyComponent {
id: string;
constructor(_params: RouteParams) {
this.id = _params.get('id');
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句