要解决Angular 9(Angular Material)用户注册后重定向不起作用的问题,可以尝试以下解决方法:
this.authService.registerUser(userData).subscribe(
(response) => {
// 用户注册成功,执行重定向
this.router.navigate(['/dashboard']);
},
(error) => {
// 处理注册失败的情况
}
);
const routes: Routes = [
// 其他路由配置
{ path: 'dashboard', component: DashboardComponent },
];
import { Router } from '@angular/router';
constructor(private router: Router) {}
// 在需要的地方执行重定向
this.router.navigate(['/dashboard']);
const routes: Routes = [
// 其他路由配置
{ path: 'register', redirectTo: '/dashboard', pathMatch: 'full' },
{ path: 'dashboard', component: DashboardComponent },
];
通过上述解决方法之一,您应该能够解决Angular 9(Angular Material)用户注册后重定向不起作用的问题。