这是我的应用代码:
import {bootstrap, Component, View} from 'angular2/angular2';
import { ROUTER_PROVIDERS, Router, RouterOutlet, RouteConfig,RouterLink, Location} from 'angular2/router';
import { About } from "./components/about";
@Component({
selector: 'my-app',
template:'<h1>{{title}}</h1>'
})
@RouteConfig( [
{ path: "/", as: "Home", component: AppComponent },
{ path: "/about", as: "About", component: About}
] )
class AppComponent {
public title = 'Home';
}
bootstrap(AppComponent);
这是我的组件的代码:
import {bootstrap, Component, View} from 'angular2/angular2';
@Component({
selector:"about",
template:'<h1>{{title}}</h1>'
})
export class About{
public title = 'About';
}
出于某种原因,如果我从@RouteConfig
删除About,我至少可以显示主页面,但是通过指向about组件的路径,我总是得到:
Uncaught Uncaught SyntaxError: Unexpected token <
Evaluating http://test.local/src/app/components/about
有人知道发生了什么事吗?
答案 0 :(得分:0)
http://test.local/src/来自哪里? 由于您尚未指定LocationStrategy Angular,因此默认情况下使用PathLocationStrategy。在这种情况下,您需要使用APP_BASE_HREF指定基本URL的值,例如:
bootstrap(AppComponent,[ROUTER_PROVIDERS, 提供(APP_BASE_HREF,{useValue:'/'}) ]);