Angularjs Angular 4+中域名后的动态路由问题;

Angularjs Angular 4+中域名后的动态路由问题;,angularjs,angular,angular-ui-router,angular4-router,Angularjs,Angular,Angular Ui Router,Angular4 Router,在Angular 4项目中,我在route处有一个容器组件: const appRoutes: Routes = [ { path: '', component: HomeComponent}, { path: '404', component: NotfoundComponent}, { path: 'pages/:page-handle', component: StaticpagesComponent }, { path: 'blog/:blog-h

在Angular 4项目中,我在route处有一个容器组件:

    const appRoutes: Routes = [
    { path: '', component: HomeComponent},
    { path: '404', component: NotfoundComponent},
    { path: 'pages/:page-handle', component: StaticpagesComponent },
    { path: 'blog/:blog-handle', component: StaticpagesComponent },
    { path: 'idx', component: ListingComponent },
    { path: 'area/:area-name', component: AreadetailComponent },
    { path: 'zip-code/:zip-name', component: ZipdetailComponent },
    { path: ':agent-handle', component:AgentComponent },
    // otherwise redirect to home
    { path: '**', redirectTo: '404' }
];
所以我想访问域名后的不同组件 比如说

  • 然后应该调用ZipdetailComponent

  • 然后应该调用AreadetailComponent

  • 那你应该打电话 静态页面组件

问题:域后的任何名称进入以下路径:

 { path: ':agent-handle', component:AgentComponent },

有人知道我该怎么解决吗?

路线的顺序很重要。您应该在通配符匹配之前定义
'
路由,以便在没有其他匹配的情况下匹配

从角路由文档中

路由在配置中的顺序很重要,这是由设计决定的。路由器在匹配路由时使用首次匹配获胜策略,因此更具体的路由应置于不太具体的路由之上


路线的顺序很重要。您应该在通配符匹配之前定义
'
路由,以便在没有其他匹配的情况下匹配

从角路由文档中

路由在配置中的顺序很重要,这是由设计决定的。路由器在匹配路由时使用首次匹配获胜策略,因此更具体的路由应置于不太具体的路由之上


根据您定义的路线,应该是:

http://localhost:8080/zipcode/:zip-name  
http://localhost:8080/area/:area-name  
http://localhost:8080/pages/:page-handle

根据您定义的路线,应为:

http://localhost:8080/zipcode/:zip-name  
http://localhost:8080/area/:area-name  
http://localhost:8080/pages/:page-handle

是@Ankit您是对的,但是
{path:':page handle',component:StaticpagesComponent},{path:':agent handle',component:AgentComponent},然后它总是调用第一个StaticpagesComponent,那么如何调用AgentComponent呢?如果我通过了,那么你应该创建像
agent/:handle
page/:handle
这样的路由。是的@Ankit你是对的,但是
{path:':page handle',component:StaticpagesComponent},{path:':agent handle',component:AgentComponent},然后它总是调用第一个StaticpagesComponent,那么如何调用AgentComponent呢?如果我通过了,那么你应该创建你的路由,比如
agent/:handle
page/:handle
。你不需要做任何更改。例如:如果你运行localhost:8080/zip code/27511,它将自动进入ZipDetailComponent Hi抱歉,我的朋友,我可能写错了,但我想知道如何获得不同的组件,这可能是不可能的。您不需要任何更改。例如:如果您运行localhost:8080/zip code/27511,它将自动进入ZipDetailComponent抱歉,我的朋友,我在写作中犯了错误,但我想知道怎样才能得到不同的组件,这可能是不可能的。