相关疑难解决方法(0)

如何获得角度2的当前路线自定义数据?

我设置的路线如下

const appRoutes: Routes = [
  {
    path: 'login',
    component: LoginComponent,
    data: {
      title: 'Login TTX'
    }
  },
  {
    path: 'list',
    component: ListingComponent,
    data: {
      title: ' TTX Home Page',
      module:'list'
    }
  },
  {
    path: '',
    redirectTo: '/login',
    pathMatch: 'full'
  },
];
Run Code Online (Sandbox Code Playgroud)

现在,当我来'/list' 路线然后'listing.component.ts'我写下面的代码

export class ListingComponent {

  public constructor(private router:Router) {
      //here how i can get **data** of **list** routes

  }
}
Run Code Online (Sandbox Code Playgroud)

angular2-routing angular

25
推荐指数
5
解决办法
3万
查看次数

Angular 2获取当前路线

因此,我需要以某种方式检查我是否在主页上并做某事,而在其他页面中则不这样做.还在所有页面上导入该组件.

如果我在主页上,如何检测该组件?

谢谢

routes typescript angular2-routing angular

15
推荐指数
3
解决办法
5万
查看次数

如何访问服务中的角度 2/4 中为特定路线添加的静态数据?

const routes: Routes = [
    {
        path: 'somepath',
        component: SomeComponent,
        data: {
            showSidebar: true,
            title: 'test'
        }
    },
    {
        path: 'somepath2',
        component: SomeComponent2,
        data: {
            showSidebar: false,
            title: 'test2'
        }
    }
];
Run Code Online (Sandbox Code Playgroud)

如何从当前激活的路线访问数据对象?如果我当前的路由是 localhost:4200/app/somepath2 那么我想访问数据: { showSidebar: false, title: 'test2' }

angular2-routing angular

5
推荐指数
1
解决办法
2546
查看次数

Angular - 在应用组件中获取路由数据

我配置了以下路由 app-routing.module.ts

const routes: Routes = [
  {
    path: 'abc/:id', component: AbcComponent, data: { category: 'Public' }
  },
  {
    path: 'xyz/:id/tester/:mapId', component: XyzComponent, data: { category: 'Private' }
  },
  { path: '**', redirectTo: '/page-not-found', pathMatch: 'full'}
]
Run Code Online (Sandbox Code Playgroud)

app.component.ts我想根据传递的 URL 获取每个路由的类别:

例如:go to http://myapp.com/abc/123 should return category as Public going to http://myapp.com/xyz/123/tester/456 should return category asPrivate

这是我到目前为止所拥有的:

constructor(
    private activatedRoute: ActivatedRoute,
    private router: Router
)
{
  checkRouteAndGetCategory()
}

checkRouteAndGetCategory()
{
  this.router.events.pipe(
        filter(event => event instanceof NavigationEnd),
        map(() => …
Run Code Online (Sandbox Code Playgroud)

typescript angular-routing angular

4
推荐指数
1
解决办法
1027
查看次数