Estoy jugando con VaadinRouter, tratando de proteger las rutas. A continuación puede ver el código onBeforeEnter de mi componente para proteger:
authenticatedDummy = true; public onBeforeEnter( location: RouterLocation, commands: PreventAndRedirectCommands ): Promise<unknown> | RedirectResult | undefined { if (this.authenticatedDummy) { console.log('OnBeforeEnter'); return new Promise(resolve => { setTimeout(() => { resolve(commands.redirect('/home')); }, 2000); }); } return undefined; } No entiendo por qué el enrutador me enruta, si authenticatedDummy es falso. Mientras leo el código, if authenticatedDummy is true, redirect me to '/home' .
¿Es esta la forma correcta de leerlo o estoy pasando por alto algo?
He construido el script mal. Debería haber sido:
public onBeforeEnter( location: RouterLocation, commands: PreventAndRedirectCommands ): Promise<unknown> | RedirectResult | undefined { if (!this.isAuthorized()) { console.log('Guarded!'); return new Promise(resolve => { setTimeout(() => { resolve(commands.redirect('/')); }, 2000); }); } return undefined; }¡Está funcionando así!