ngx-rocket yeomanジェネレータを使用してAngular 4アプリでいくつかのページのルートを設定しました。たとえば、「eat」というページを作成し、www.haakon.ioのホームページに移動してeatリンクをクリックすると、そのページに移動します。ブラウザにそのリンクを入力しようとすると、たとえばhttp://www.haakon.io/eatのようになり、そこでナビゲートしようとすると404エラーページが表示されます。私はこれが深いリンクの問題と関係していることを知っていますが、角度1.5のソリューションのいくつかを試してみて、うまくいきません。具体的に私は私のindex.htmlページに設定されたベースのhrefを持っています。ここではAngular 4 ngx-rocketディープリンクルーティングの問題
<base href="/"/>
は私のアプリ-routing.module.tsファイルです。ここで
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [
// Fallback when no prior route is matched
{ path: '**', redirectTo: '', pathMatch: 'full' }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
providers: []
})
export class AppRoutingModule { }
は私route.service.tsです:
import { Routes } from '@angular/router';
import { ShellComponent } from './shell/shell.component';
/**
* Provides helper methods to create routes.
*/
export class Route {
/**
* Creates routes using the shell component and authentication.
* @param routes The routes to add.
* @return {Routes} The new routes using shell as the base.
*/
static withShell(routes: Routes): Routes {
return [{
path: '',
component: ShellComponent,
children: routes
}];
}
}
そして最後に、私の食べ-routing.module.ts:
import { Route } from '../core/route.service';
import { extract } from '../core/i18n.service';
import { EatComponent } from './eat.component';
const routes: Routes = Route.withShell([
{ path: 'eat', component: EatComponent, data: { title: extract('Eat') } }
]);
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
providers: []
})
export class EatRoutingModule { }