Angular2路由/深层链接不能与Apache 404一起使用
发布时间:2020-12-17 08:03:50 所属栏目:安全 来源:网络整理
导读:我正在关注Angular 2路由示例。使用“精简”网络服务器,我能够从根和深层链接工作导航,但使用Apache我可以从根导航,但是当跟随链接指向路由时,会获得404 Not Found错误。 例如,以下URL对npm由端口3000启动的“lite”Web服务器起作用。 http://localhost
我正在关注Angular 2路由示例。使用“精简”网络服务器,我能够从根和深层链接工作导航,但使用Apache我可以从根导航,但是当跟随链接指向路由时,会获得404 Not Found错误。
例如,以下URL对npm由端口3000启动的“lite”Web服务器起作用。 http://localhost:3000/crisis-center/2 但是在端口80上运行Apache的下一个URL失败了。 http://localhost/crisis-center/2 The requested URL /crisis-center/2 was not found on this server. 我确实尝试了一些针对类似Angular 1问题推荐的.htaccess解决方案,但没有运气。如果有人在Apache上有Angular 2路由和深层链接工作,请告诉我你是如何实现的。 @RouteConfig([ { // Crisis Center child route path: '/crisis-center/...',name: 'CrisisCenter',component: CrisisCenterComponent,useAsDefault: true },{path: '/heroes',name: 'Heroes',component: HeroListComponent},{path: '/hero/:id',name: 'HeroDetail',component: HeroDetailComponent},{path: '/disaster',name: 'Asteroid',redirectTo: ['CrisisCenter','CrisisDetail',{id:3}]} ]) Boot.ts import {bootstrap} from 'angular2/platform/browser'; import {ROUTER_PROVIDERS} from 'angular2/router'; import {AppComponent} from './app.component'; bootstrap(AppComponent,[ROUTER_PROVIDERS]);
因为上面的答案并没有真正回答你是否想要它与Apache一起工作的问题。
HashLocationStrategy仍然是一个选项,但如果您希望它在Apache上工作,您需要执行以下操作:
在与index.html相同的位置创建一个新文件.htaccess。以下代码将在里面: <IfModule mod_rewrite.c> Options Indexes FollowSymLinks RewriteEngine On RewriteBase /crisis-center/ RewriteRule ^index.html$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.html [L] </IfModule> (注意,在问题中,index.html内的< base href =“/ crises-center /”>应该与RewriteBase相同) 答案改编自Angular 2 routing and direct access to a specific route : how to configure Apache?的问答 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- clearance + bootstrap3 + simple_form 的 登陆界面
- angular – 如何编写可重用的组件/模块?
- macos – 如何将OSX launchd plist的参数添加到管道输出到日
- scala – 对java.io.IOException的Gatling检查:远程关闭
- Scala中非严格,不变的,无记忆的无限系列
- Bootstrap 学习之 (十七)------ 面板
- 我可以在Scala中一次性从多个包导入?
- CXF soup webservice 动态客户端调用工具类
- Angular2开发前端是否需要结合webpack?
- angularjs – 如何将升级的Angular 1服务/工厂注入ES5中的A