1
すべてはタイトルにあります:redirectTo
プロパティを使用して相対URLにリダイレクトできますか?次のようにAngular2ルーティング:redirectTo相対URL
マイ(簡体字)、ルーティングは次のようになります。私は、エラーがそのダッシュボードが不明であると言って発生URL/admin/
に到達したい場合
{path: 'login', children: []},
{path: '', children: [ // made here for future guards
{path: 'admin', children: [
{path: 'dashboard', children: []}
{path: '', redirectTo: 'dashboard'}
]}
]},
{path: '', redirectTo: 'login', pathMatch: 'full'}
マイルーティングことを除いて、うまく機能しています。しかし、redirectTo: 'admin/dashboard'
でルーティングが機能します。
rediretcTo
で相対ルーティングを使用する方法はありますか?
EDIT全経路:
app.module
{ path: 'login', component: LoginComponent, children: [] },
{ path: 'signup', component: SignupComponent, children: [] },
{ path: '', redirectTo: '/login', pathMatch: 'full' },
...loggedRoutes
logged.module
{ path: 'logged', component: LoggedComponent, children: [
{ path: 'profile', component: ProfileComponent, children: [] },
...adminRoutes,
...mainRoutes
] },
admin.module
{ path: 'admin', component: AdminComponent, children: [
{ path: 'dashboard', component: DashboardComponent, children: [] },
{ path: 'validation/:objectid', component: ValidationComponent, children: [] },
{ path: '', redirectTo: '/logged/admin/dashboard' },
] },
main.module
{ path: 'main', component: MainComponent, children: [
{ path: 'error', component: ErrorComponent, children: [] },
{ path: 'last', component: LastComponent, children: [] },
{ path: 'process', component: ProcessComponent, children: [] },
{ path: 'crt', component: CrtComponent, children: [] },
{ path: '', redirectTo: '/logged/main/error' },
] },
私は既にそれを試みていて、うまくいきませんでした。どうやら、pathMatchを追加すると、URLはパラメータと完全に同じである必要があります。接頭辞があるように私は '接尾辞 'を持つことを期待していましたが、残念なことに、そうではありません。 – trichetriche
あなたの全体のルート配列を投稿してもよろしいですか?私の場合、それはそのように動作しますが、同じレベルの空のパスに対して2つのオプションがあるので、 'admin'パスを' login'と同じレベルに置こうとします。将来もガードを追加することができます。 –