【问题标题】:router outside canActivate: [AuthGuard] doesn't workcanActivate 外的路由器:[AuthGuard] 不起作用
【发布时间】:2018-07-04 11:05:07
【问题描述】:

我的路由有问题。

我尝试使用此代码:

const routes: Routes = [
  {
    path: 'home', component: HomeComponent, canActivate: [AuthGuard], children: [
      { path: 'events', component: EventsComponent },
      { path: 'package', component: PackageComponent },
      { path: 'settings', component: SettingsComponent }
    ]
  },
  { path: 'login', component: LoginComponent },
  { path: '**', redirectTo: 'home' },
  { path: "register", component: RegisterComponent },
  { path: "usersforgetpassword", component: ResetPassComponent }
];

导航不起作用,忘记密码(ResetPassComponent)和新帐户(RegisterComponent)。

HTML代码:

<StackLayout>
        <Label [nsRouterLink]="['/usersforgetpassword']" class="text-center footnote">
            <FormattedString>
                <Span text="Forgot password?  "></Span>
            </FormattedString>
        </Label>
    </StackLayout>
    <StackLayout>
        <Label [nsRouterLink]="['/register']" class="text-center footnote">
            <FormattedString>
                <Span text="New Account "></Span>
            </FormattedString>
        </Label>
    </StackLayout>

请问,我的路由器有什么问题吗?看不懂。

谢谢

【问题讨论】:

  • 你在用page-router-outlet吗?
  • 是的&lt;page-router-outlet&gt;&lt;/page-router-outlet&gt;

标签: angular typescript nativescript router guard


【解决方案1】:

请放置这些

{ path: "register", component: RegisterComponent },
  { path: "usersforgetpassword", component: ResetPassComponent }

之前

 { path: '**', redirectTo: 'home' } 

【讨论】:

    【解决方案2】:

    通配符路由应该始终放在最后,否则下面的路由将不起作用,因为它匹配所有可能的字符串。

    参考:https://angular.io/guide/router#configuration

    【讨论】:

      猜你喜欢
      • 2016-11-19
      • 1970-01-01
      • 2019-02-26
      • 2019-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-23
      相关资源
      最近更新 更多