2015-12-21 41 views
3

我有路由问题。Angular2路由。在网址结尾的斜线

当我在URL“myapp.com/route”像从“myapp.com/route/”我的资源装载结束多了一个斜线加上“myapp.com/route/......”。

例如:我必须从'myapp.com/starwars.js'加载库,但使用斜杠将从'myapp.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 { } 

谢谢您的解答!

回答

0

我不知道你怎么包括您starwars.js但相对于当前的URL可能。这就是为什么当你的地址有斜线时,它被解析为错误的地址。

你可以尝试添加基本URL到您的网页:

<base href="/"> 

有了这个,你将确保所有的相对地址去反对`/``得到解决。

欲了解更多信息,请参阅Angular 2 doc here

+0

这是问题对我来说,我的标签是在错误的地方,哎呦!谢谢! – trickpatty