为什么 Vaadin Router 在未通过身份验证时路由我?

Why does VaadinRouter route me when not authenticated?

我正在摆弄 VaadinRouter,试图保护路由。 下面你可以看到我要保护的组件的onBeforeEnter代码:

    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;
      }

我不明白为什么路由器路由我,如果 authenticatedDummy 是假的。 当我阅读代码时,if authenticatedDummy is true, redirect me to '/home' .

这是正确的阅读方式还是我忽略了什么?

我构建的脚本有误。 应该是:

 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;
      }

原来是这样的!