2017-10-04 15 views
0

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 { } 

答えて

0

調査の結果、ファイルがサーバーから削除され、サーバーレベルの既定のルーティングに影響が出ていることが判明しました。

最初はこの問題を削除することを考えましたが、誰かを助ける場合に回答を投稿することにしました。

ソリューションは、次の内容の.htaccessファイルを作成することでしたし、ホスト上のルートフォルダでそれを置く:

# If the request is a file, folder or symlink that exists, serve it up 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^(.+)$ - [S=1] 

# otherwise, serve your index.html app 
RewriteRule ^(.+)$ /index.html 

今に直接入力してアクセスすることがwww.haakon.io/artブラウザまたは他のウェブサイトからのリンク。

関連する問題