在Angular 2(v6)中进行路由

时间:2018-09-20 16:23:10

标签: angular

我在Angular 2(v6)中的路由遇到一些问题

该网站的结构如下:

(root,site.com /)

---- subfolder1(site.com/subfolder1)

---- subfolder2(site.com/subfolder2)

---- client(site.com/client)<< Anuglar网站

部署时,我们使用的是:ng build --prod --deploy-url = / client /

出于某种原因,当我们导航到site.com/client/quote/88b02e09-511b-40c5-a64a-a3aeb2b9d239时,它总是转到PageNotFoundComponent

我们的路线参数:

  

const路由:路由= [{路径:”,组件:QuoteSearchComponent   },{路径:'quote /:guid',组件:QuoteComponent},{路径:   '**',组件:PageNotFoundComponent}];

     

main.9a26b5fe0012f4ac3aae.js:1 GuardsCheckEnd(id:1,url:   '/ quote / 88b02e09-511b-40c5-a64a-a3aeb2b9d239',urlAfterRedirects:   '/ quote / 88b02e09-511b-40c5-a64a-a3aeb2b9d239',状态:Route(url:'',   路径:''){Route(url:'quote / 88b02e09-511b-40c5-a64a-a3aeb2b9d239',   path:'quote /:guid')},shouldActivate:true)   main.9a26b5fe0012f4ac3aae.js:1 e {id:1,url:   “ / quote / 88b02e09-511b-40c5-a64a-a3aeb2b9d239”,urlAfterRedirects:   “ / quote / 88b02e09-511b-40c5-a64a-a3aeb2b9d239”,状态:e,   shouldActivate:true} main.9a26b5fe0012f4ac3aae.js:1路由器事件:e   main.9a26b5fe0012f4ac3aae.js:1 ResolveStart(id:1,url:   '/ quote / 88b02e09-511b-40c5-a64a-a3aeb2b9d239',urlAfterRedirects:   '/ quote / 88b02e09-511b-40c5-a64a-a3aeb2b9d239',状态:Route(url:'',   路径:''){Route(url:'quote / 88b02e09-511b-40c5-a64a-a3aeb2b9d239',   path:'quote /:guid')})main.9a26b5fe0012f4ac3aae.js:1 e {{id:1,url:   “ / quote / 88b02e09-511b-40c5-a64a-a3aeb2b9d239”,urlAfterRedirects:   “ / quote / 88b02e09-511b-40c5-a64a-a3aeb2b9d239”,状态:e}   main.9a26b5fe0012f4ac3aae.js:1路由器事件:e   main.9a26b5fe0012f4ac3aae.js:1 ResolveEnd(id:1,url:   '/ quote / 88b02e09-511b-40c5-a64a-a3aeb2b9d239',urlAfterRedirects:   '/ quote / 88b02e09-511b-40c5-a64a-a3aeb2b9d239',状态:Route(url:'',   路径:''){Route(url:'quote / 88b02e09-511b-40c5-a64a-a3aeb2b9d239',   path:'quote /:guid')})main.9a26b5fe0012f4ac3aae.js:1 e {{id:1,url:   “ / quote / 88b02e09-511b-40c5-a64a-a3aeb2b9d239”,urlAfterRedirects:   “ / quote / 88b02e09-511b-40c5-a64a-a3aeb2b9d239”,状态:e}   main.9a26b5fe0012f4ac3aae.js:1路由器事件:t   main.9a26b5fe0012f4ac3aae.js:1 ActivationEnd(path:'quote /:guid')   main.9a26b5fe0012f4ac3aae.js:1 t {快照:t}   main.9a26b5fe0012f4ac3aae.js:1路由器事件:t   main.9a26b5fe0012f4ac3aae.js:1 ChildActivationEnd(path:'')   main.9a26b5fe0012f4ac3aae.js:1 t {快照:t}   main.9a26b5fe0012f4ac3aae.js:1路由器事件:e   main.9a26b5fe0012f4ac3aae.js:1 NavigationEnd(id:1,url:   '/ quote / 88b02e09-511b-40c5-a64a-a3aeb2b9d239',urlAfterRedirects:   '/ quote / 88b02e09-511b-40c5-a64a-a3aeb2b9d239')   main.9a26b5fe0012f4ac3aae.js:1 e {id:1,url:   “ / quote / 88b02e09-511b-40c5-a64a-a3aeb2b9d239”,urlAfterRedirects:   “ / quote / 88b02e09-511b-40c5-a64a-a3aeb2b9d239”}

1 个答案:

答案 0 :(得分:0)

我需要有关您要做什么的更多信息,但请参考我的示例作为指导:

最佳实践表明,您始终需要在语句中放入路径值。

import { RouterModule, Routes } from '@angular/router'
import { HomeComponent } from './components/home/home.component';
import { AboutComponent  } from './components/about/about.component'
import { HeroesComponent } from './components/heroes/heroes.component'

const APP_ROUTES: Routes = [
    { path: 'home', component: HomeComponent},
    { path: 'about', component: AboutComponent},
    { path: 'heroes', component: HeroesComponent},
    { path: '**', pathMatch: 'full', redirectTo: 'home'}
]

export const APP_ROUTING = RouterModule.forRoot(APP_ROUTES, { useHash: true });