【问题标题】:Routes probleme with an Angular 5 projectAngular 5 项目的路由问题
【发布时间】:2018-09-23 16:18:46
【问题描述】:

嗯,我是 Angular 的新手,我正在尝试使用这个项目:

https://github.com/telerik/ng2-dashboard

但我无法理解路线是如何制作的。这不是我习惯使用 Routes 的方式。

即使我在登录组件中添加了一些内容,它也会将我直接重定向到仪表板!

非常感谢您的帮助。

【问题讨论】:

    标签: angular routes angular5 dashboard


    【解决方案1】:

    不幸的是,我不知道您的确切问题是什么,但从您提供的 github 项目看来,登录组件中有一个硬编码用户,应该会导致您重定向到 /profile。如果您想返回退出组件或清除浏览器缓存/cookie,您可以使用退出功能阻止它发生。

    另一方面,路由看起来像一个主路由文件,它分支到具有自己路由的子模块。我将尝试在一个糟糕的箭头图中展示一切如何连接......

    app.module.ts --gets all routes--> app.common.ts 
    app.common.ts --calls master route module --> app-routing.module.ts 
    app-routing.module.ts --gets parent component/routes--> app.route.ts 
    app.route.ts --calls all child modules --> ex.dashboard.module.ts
    ex: dashboard.module.ts -- gets child routes/components --> ex: dashboard.common.ts
    ex: dashboard.common.ts --gets child routes --> ex: dashboard.routes.ts
    ex: dashboard.routes -- sets/creates child routes --
    

    希望这对您有所帮助,并让您更好地了解该项目如何创建路线。

    【讨论】:

      【解决方案2】:

      我认为,@HostBinding 在以下两个文件中全局监听:-

      signin.component.ts 文件

      @HostBinding('attr.id') protected get id(): string {
              return 'signin';
      }
      @HostBinding('class') protected get appClass(): string {
              return 'signin';
      }
      

      dashboard.component.ts 文件,

      @HostBinding('attr.id') get get_id() { return 'dashboard'; }
      @HostBinding('class') get get_class() { return 'dashboard'; }
      

      您能否尝试在dashboard.component.ts 中为@HostBinding 注释这些行 并再次尝试测试。希望它会起作用。

      【讨论】:

      • 同样的问题,即使我在构造函数中添加 http 服务,“主页”成为我的第一页,但无法登录!
      猜你喜欢
      • 1970-01-01
      • 2023-03-27
      • 2023-03-06
      • 2016-06-11
      • 1970-01-01
      • 2013-04-17
      • 1970-01-01
      • 1970-01-01
      • 2016-12-22
      相关资源
      最近更新 更多