Angular2路由.在url末尾斜杠
Angular2 Routing. Slash in the end of url
我在路由方面遇到问题。
当我在url"myapp.com/route"中添加一个斜杠,就像"myapp.com/sroute/"一样,我的资源从"myapp.microsoft.com/route/…"加载。
例如:我有一个库必须从"myapp.com/starwars.js"加载,但使用斜杠,它将从"myapps.com/route/starwars.js"加载。http://prntscr.com/9gpeen
但没有斜线是正常的http://prntscr.com/9gpepv
代码
import {Component} from 'angular2/core';
import {Route, RouteConfig, ROUTER_DIRECTIVES} from 'angular2/router'
import {NotFound} from './notfound/notfound';
import {TimerComponent} from './timer/timer.component'
@Component({
selector: 'my-app',
template:`
<a [routerLink]="['Timer']">Timer</a>
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES]
})
@RouteConfig([
{ path: 'timer/', name: 'Timer', component: TimerComponent},
new Route({path: '/**', component: NotFound})
])
export class AppComponent { }
谢谢你的回答!
我不知道如何包含starwars.js
,但它可能是相对于当前url的。这就是为什么当你的地址中有斜杠时,它会被解析为错误的地址。
您可以尝试将基本url添加到您的页面:
<base href="/">
这样,您将确保所有相对地址都将根据"/"进行解析。
有关更多信息,请参阅Angular 2文档。
相关文章:
- 使用ui路由器实现动态URL路由的最佳方式是什么
- Ui路由器未按url路由
- 使用ui路由器在URL路由中创建一个必需的参数
- Javascript 无法解析正确的图像路径,当使用 URL 路由在 ASP.Net 中请求页面时
- AngularJS ui-router 中的 URL 路由参数
- 有没有一种方法可以在express.js中的url路由中执行动态键/值参数
- 使用正则表达式的Url路由子字符串
- Javascript(Jquery)调用MVC3 Controller/Action/ID的URL路由问题,返回404,
- Backbone.js:url路由末尾的尾部斜杠
- 在本地基于文件的应用程序中(使用file://),是否可以使用AngularJS进行HTML5模式URL路由
- Angular的url路由不能直接访问
- AngularJS为同一个URL路由多个ui-view
- 从Express服务的客户端React应用上的一致url路由
- 创建一个模板url路由脚本
- Url路由不工作在我的PHP代码
- Javascript MVC Url路由组件,路由在两边
- URL路由到子视图
- react-router-component将所有url路由到同一个组件
- Javascript将/url路由到函数
- AngularJS相对url路由问题