如何将自定义数据添加到路由? [英] How to add custom data to a route?

查看:81
本文介绍了如何将自定义数据添加到路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在定义路线时添加一些自定义数据来进行路由.

I want to add some custom data to route when I define the routes.

我该怎么做?

like:

{
  path: 'department',
  component: DepartmentComponent,

  customdata: {
    name: 'foo',
    age: '23'
  }
}

我不希望自定义数据显示在URL中.我只是在内部使用.

I don't want the custom data to display in URL. I just use it internally.

推荐答案

您可以像这样为路由定义自定义数据:

You can define the custom data to the route like this:

[
   {path: 'inbox', data: {name: 'foo', age: 23}},
]

阅读如下:

class ConversationCmp {
    constructor(r: ActivateRoute) {
         r.data.subscribe((p) => {
              console.log(p);
         });
    }
}

它是在Route界面上定义的:

export interface Route {
  path?: string;
  ...
  data?: Data;
}

这篇关于如何将自定义数据添加到路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆