【发布时间】:2016-09-20 04:42:49
【问题描述】:
我使用 angular 2 进行路由,使用节点进行本地托管。
当我对路线使用“useAsDefault:true”时,导航栏链接不再起作用,当我希望 URL 转到 http://localhost/home 时,URL 转到 http://localhost/(空白页)
一个我删除了导航栏正常工作的标志,我可以去 /home 路线,但我去空白页
谁能解释为什么默认标志不能正常工作?
App.Component.ts
@RouteConfig([
{ path: '/home', name: 'Home', component: HomeComponent /*, useAsDefault : true */},
{ path: '/articles', name: 'Posts', component: PostsComponent },
{ path: '/detail/:id', name: 'PostDetail', component: PostDetailComponent },
{ path: '/login', name: 'Login', component: LoginComponent },
])
App.Component.html
<ul class="topnav">
<li><a [routerLink]="['Home']">Home</a></li>
<li><a [routerLink]="['Posts']">Articles</a></li>
<li><a href="#p">Publisher</a></li>
<li><a [routerLink]="['Login']">Login</a></li>
</ul>
<router-outlet></router-outlet>
Main.ts
import { bootstrap } from '@angular/platform-browser-dynamic';
import { AppComponent } from './app.component';
import { HTTP_PROVIDERS } from '@angular/http';
import { ROUTER_PROVIDERS } from '@angular/router-deprecated';
bootstrap(AppComponent, [ROUTER_PROVIDERS, HTTP_PROVIDERS]);
index.html
<html>
<head>
<script>document.write('<base href="' + document.location + '" />');</script>
<title>Blog</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles/styles.css">
<!-- Polyfill(s) for older browsers -->
<script src="node_modules/core-js/client/shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<!-- 2. Configure SystemJS -->
<script src="systemjs.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
</head>
<!-- 3. Display the application -->
<body>
<blog-app>Blog Loading...</blog-app>
</body>
</html>
【问题讨论】:
标签: javascript angularjs typescript routing angular