如何将自定义数据添加到路由?

时间:2017-08-02 03:27:07

标签: angular

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

我该怎么做?

喜欢:

{
  path: 'department',
  component: DepartmentComponent,

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

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

2 个答案:

答案 0 :(得分:5)

您可以将路径的自定义数据定义为:

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

答案 1 :(得分:2)

我是按照以下方式做的:

$rows = Excel::load('storage\\app\\public\\upload\\Funiture.xlsx)->get();
<span>Furniture Registration Number : <b>{{ $rows[0][1] }}</b></span>

$rows = Excel::load('storage\\app\\public\\upload\\Funiture.xlsx, function($reader){$reader->noHeading(); $reader->skipRows(3); })->get();;

@foreach ($rows as $key => $value)
  <tr>
    <td>{{ $value->[0] }}</td>
    <td>{{ $value->[1] }}</td>
    <td>{{ $value->[2] }}</td>
    <td>{{ $value->[3] }}</td>
  </tr>
@endforeach

我用它来为路由添加角色自定义属性,以便只能对具有特定角色的用户进行访问,我在路由中设置。

相关问题