我在angular2应用程序上配置我的路线:
所以,在app.routes.ts
:
export const ROUTES: Routes = [{
path: '', redirectTo: 'login', pathMatch: 'full'
}, {
path: 'app', loadChildren: () => System.import('./layout/layout.module')
}, {
path: 'login', loadChildren: () => System.import('./login/login.module')
}, {
path: 'validate/:id/:token', loadChildren: () => System.import('./validate/validate.module')
}, {
path: 'error', component: ErrorComponent
}, {
path: '**', component: ErrorComponent
}
];
目前,我正面临两个问题:
http://localhost:3000
时,它被重定向到http://localhost:3000/Living%20User%20Platform#/login
:我不太明白为什么将此Living%20User%20Platform#
添加到网址,而不是http://localhost:3000/login
。validate/:id/:token
。然而,当我在浏览器上写这个URL(http://localhost:3001/Living%20User%20Platform#/validate?id=sdfsdf&token=sdfsdf)时,它会转到错误路径: ValidateModule.ts
:
export const routes = [
{path: '', component: Validate, pathMatch: 'full'}
];
@NgModule({
declarations: [
// Components / Directives/ Pipes
Validate
],
imports: [
CommonModule,
FormsModule,
RouterModule.forChild(routes),
]
})
export default class ValidateModule {
static routes = routes;
}
有什么想法吗?
答案 0 :(得分:2)
您的路线正在Living%20User%20Platform
,因为您可能未在HTML中设置正确的<base href="/">
,而您需要使用UTL validate/:id/:token
检查网址http://localhost:3001/Living%20User%20Platform#/validate/sdfsdf/sdfsdf
< / p>
答案 1 :(得分:0)
我已经改变了我的路线(validate/:id/:token
只需validate
路径):
export const ROUTES: Routes = [{
path: '', redirectTo: 'login', pathMatch: 'full'
}, {
path: 'app', loadChildren: () => System.import('./layout/layout.module')
}, {
path: 'login', loadChildren: () => System.import('./login/login.module')
}, {
path: 'validate', loadChildren: () => System.import('./validate/validate.module')
}, {
path: 'error', component: ErrorComponent
}, {
path: '**', component: ErrorComponent
}
];
为了使用ActivatedRoute
constructor(private router: Router, private route: ActivatedRoute, private userService: UsersService)
{
this.user = undefined;
}
ngOnInit():void {
this.route.queryParams.subscribe(params => {
this.id = params['id'] || undefined;
this.token = params['token'] || undefined;
});
}