私は角度4のシングルページアプリケーションを持っています。ページを更新するか、ブラウザに有効なURLを入力すると、アプリのルートルートにリダイレクトされます。角度4リフレッシュ時にルートにリダイレクト
すべてのリクエストを/index.htmlにリダイレクトするようにnginxの設定を変更しました。ブラウザの更新時に404を取得するという初期の問題を修正しました。
server {
listen 80;
server_name bla.com www.bla.com
location/{
root /home/admin/web/bla.com/public_html;
index index.html index.htm;
try_files $uri $uri/ =404;
}
error_page 404 /index.html;
error_page 500 502 503 504 /50x.html;
# To allow POST on static pages
error_page 405 =200 $uri;
location = /50x.html {
root /usr/share/nginx/html;
}
}
**編集**
角度ルーティングは単にRouterModuleによって処理されます:
// ...
import { RouterModule, Routes } from '@angular/router';
// ...
const appRoutes: Routes = [
{ path: '', component: DashboardComponent, canActivate: [AuthGuard] },
{ path: 'login', component: LoginComponent },
{ path: 'register', component: RegisterComponent },
{ path: 'dashboard', component: DashboardComponent, canActivate: [AuthGuard] },
{ path: 'clients', component: ClientsComponent, canActivate: [AuthGuard], children: [
{ path: 'add', component: AddClientComponent, canActivate: [AuthGuard]}
]},
{ path: 'projects', component: ProjectsComponent, canActivate: [AuthGuard], children: [
{ path: 'add', component: AddProjectComponent, canActivate: [AuthGuard] }
]},
{ path: 'profile', component: ProfileComponent, canActivate: [AuthGuard] },
{ path: 'invoices', component: InvoicesComponent, canActivate: [AuthGuard], children: [
{ path: 'invoices/new-invoice', component: NewInvoiceComponent, canActivate: [AuthGuard] }
]}
];
私は本当にHashLocationStrategyを使用したくないので、私が得ることができる方法がありますブラウザが更新されたとき、またはURLが入力されたときに正しいページを表示するための角度?
ルーティングに関連するコードをnginxで他の角度で共有してください –
[AuthGuard]が問題を引き起こしていると思います。 –
正解、ありがとう!問題が解決する場合は –