子URL委托Angular2 Router3.0.0

时间:2016-06-27 14:05:22

标签: angular angular2-routing

由于我不熟悉FE dev,Angular的URL处理并不容易。 所以我想问你几点。

我有一个网站,例如,

-----------------------------------------------------
/ <-- main page
        /company/{companyId} <-- main page redirected to.
-----------------------------------------------------
                            /employee/{empId}/profile 
                            /employee/{empId}/worklog
-----------------------------------------------------
                            /dept/{deptId}/empList
                            /dept/{deptId}/issueList
-----------------------------------------------------

one url may looks like
/company/{facebook}/employee/{james}/profile

我想象四个RouterConfigs。

(行号不是实际值,但问题描述..)

// main.ts
01 export const MainRoutes: RouterConfig = [
02  { path: '', redirectTo:'company/facebook' component: CompanyComponent},
03  { path: 'company/:companyId', component: CompanyComponent}
04 ];

// company.ts
05 export const CompanyRoutes: RouterConfig = [
06   { path: 'employee/:empId', component: EmployeeComponent},
07   { path: 'dept/:deptId', component: DeptComponent}
08 ];

// employee.ts
09 export const EmployeeRoutes: RouterConfig = [
10   { path: 'profile', component: EmployeeProfile},
11   { path: 'worklog', component: EmployeeWorklog}
12 ];

// dept.ts
13 export const DeptRoutes: RouterConfig = [
14   { path: 'empList', component: EmpListComponent},
15   { path: 'issueList', component: IssueListComponent}
16 ];

我的问题

  1. 哪一个是对的?
  2. // employee.ts (path from parent)
    09 export const EmployeeRoutes: RouterConfig = [
    10   { path: 'profile', component: EmployeeProfile},
    11   { path: 'worklog', component: EmployeeWorklog}
    12 ];
    
    // employee.ts (path from home)
    09 export const EmployeeRoutes: RouterConfig = [
    10   { path: 'company/:companyId/employee:empId/profile', component: EmployeeProfile},
    11   { path: 'company/:companyId/employee:empId/worklog', component: EmployeeWorklog}
    12 ];
    
    1. 任何方式让个人路线注册?像春天&#39; http://www.journaldev.com/3358/spring-requestmapping-requestparam-pathvariable-example&#39;

    2. 我是否必须致电&#39; provideRouter()&#39;在这样的所有路线的单一地方?

        

      http://plnkr.co/edit/?p=preview

      import { provideRouter, RouterConfig }  from '@angular/router';
      
      import { CrisisCenterRoutes } from './crisis-center/crisis-center.routes';
      import { HeroesRoutes }       from './heroes/heroes.routes';
      
      import { LoginRoutes,
               AUTH_PROVIDERS }     from './login.routes';
      
      import { CanDeactivateGuard } from './interfaces';
      
      export const routes: RouterConfig = [
        ...HeroesRoutes,
        ...LoginRoutes,
        ...CrisisCenterRoutes
      ];
      
      export const APP_ROUTER_PROVIDERS = [
        provideRouter(routes),
        AUTH_PROVIDERS,
        CanDeactivateGuard
      ];
      
    3. 子网址组件必须记住Upper组件&#39;参数

    4. 我知道这个问题也是......没有说明。但我完全陷入困惑。

      的问候。 击昏。

1 个答案:

答案 0 :(得分:1)

  1. 我更喜欢第一种声明路线的方式,因为它更易于管理
  2. 新路由器无法使用AFAIK
  3. 是的,虽然它们可以是嵌套的子路由,但必须在此处指定所有路由。
  4. 我不明白但是如果你想访问父母提供的param。你可以通过访问激活路线的父母来做到这一点。