【问题标题】:Why does VaadinRouter route me when not authenticated?为什么 Vaadin 路由器在未通过身份验证时会路由我?
【发布时间】:2021-08-28 06:26:07
【问题描述】:

我正在摆弄 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' 。

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

【问题讨论】:

    标签: javascript typescript vaadin-router


    【解决方案1】:

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

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

    它是这样工作的!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-26
      • 1970-01-01
      • 1970-01-01
      • 2013-03-27
      • 2018-12-19
      • 2021-12-20
      • 2016-12-11
      • 1970-01-01
      相关资源
      最近更新 更多