Pav*_*nta 11 url http-status-code-404 angular
我会非常简短.
我有一个带有简单导航菜单(routerLinks)的Angular项目.如果它是在本地主机上,由角度cli驱动,一切都可以工作.
但是当我将它部署在真实的服务器上时(我没有任何VPS或任何其他服务器,只有我可以放置文件的文件夹)奇怪的事情开始发生.
该应用程序功能齐全,导航功能正常,路由链接路由,但当我刷新浏览器或尝试手动写入URL行时,每次我找到404 Not found.(所以我在[domain]/home - 一切都很好,但是当我刷新浏览器时,我找不到404/home.
也许我在一个不好的地方寻找问题,这不是角度问题,而是关于HTTP请求(我不太了解它).
你知道我应该从哪里开始吗?
谢谢Pavel F.
我正在谈论的项目:http://www.pavel-challenge.cz(不,这不是广告:D)
APP-routing.module.ts
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { PassionsComponent } from './passions/passions.component';
import { QuestionComponent } from './question/question.component';
import { AboutComponent } from './about/about.component';
import { HomeComponent } from './home/home.component';
import { KnowledgeComponent } from './knowledge/knowledge.component';
const routes: Routes = [
{ path: '', redirectTo: '/home', pathMatch: 'full' },
{ path: 'home', component: HomeComponent },
{ path: 'about', component: AboutComponent },
{ path: 'knowledge', component: KnowledgeComponent },
{ path: 'questions', component: QuestionComponent },
{ path: 'passions', component: PassionsComponent },
{ path: '**', redirectTo: '/home', pathMatch: 'full' }
];
@NgModule({
imports: [ RouterModule.forRoot(routes) ],
exports: [ RouterModule ]
})
export class AppRoutingModule {}
Run Code Online (Sandbox Code Playgroud)
navbar.component.html
<ul>
<li><a routerLink="/about">About</a></li>
<li><a routerLink="/knowledge">Knowledge</a></li>
<li><a routerLink="/questions">Questions</a></li>
<li><a routerLink="/passions">Passions</a></li>
</ul>
Run Code Online (Sandbox Code Playgroud)
Pav*_*nta 26
修复:(对于Apache HTTP服务器)
我创建了.htaccess文件并将其放入提供者端的根文件夹中.
的.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
如果您在 Apache 上部署,您应该启用 mod_rewrite 模块:
sudo a2enmod 重写
然后重新启动 Apache ,sudo systemctl restart apache2
之后,按照前面的答案在 .htaccess 中进行建议的更改
| 归档时间: |
|
| 查看次数: |
10138 次 |
| 最近记录: |