如何解决如何通过MEAN堆栈从登录重定向到用户的个人资料页面?
我正在尝试使用MEAN Stack和Ionic建立社交网络。完成登录页面后,我试图直接重定向到用户页面。你能帮助我吗?下面介绍了我所拥有的:
在登录组件中:
ngOnInit() { // Esta es la función que siempre actúa. En esta se comprueba
// si al hacer el login con FB o Google,el usuario ya existe o no.
// La función de registrarlo o logearlo (en función de si existe o no el usuario)
// lo hace la función log en authService
this.socialauthService.authState.subscribe((socialuser) => {
this.socialuser = socialuser;
this.user = { // Genera el usuario que va a registrar
name : this.socialuser.name,email : this.socialuser.email
}
this.authService.log(this.user) // Comprobación de si existe el usuario y si no,lo crea
.subscribe(res => {
localStorage.setItem("token",res.token) // Asignación del token para la navegación
this.router.navigate(["perfil",this.socialuser.id]); // Navega hasta la página home
})
this.loggedIn = (socialuser != null);
});
}
配置文件组件:
export class PerfilPage implements OnInit {
public title:string;
public status: string;
public user: User;
public url: string;
public section: string; // Indica la sección a mostrar
public identity;
public token;
public stats;
constructor(
private _route: ActivatedRoute,private _router: Router,private _userService: UserService,) {
this.title = "Bienvenido a tu perfil";
this.identity = this._userService.getIdentity;
this.url = GLOBAL.url;
this.section = "Perfil Usuario"; // Carga sección por defecto
}
public ngOnInit() {
this.loadPage();
}
loadPage() {
this._route.params.subscribe(params => {
let id = params["id"]
console.log("Profile id: "+id);
})
}
}
当我尝试应用它时出现的是:
core.js:6228错误错误:未捕获(承诺中):错误:无法匹配任何路由。网址段:“ perfil / 10222931271973729” 错误:无法匹配任何路线。网址段:“ perfil / 10222931271973729”
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。