2016-08-24 58 views
0

我正在尝试开发应用程序。在路线延迟加载)在角2(RC5)的帮助下。我发现我无法为任何路由添加书签,即使我试图直接在URL中添加链接,但它不起作用,我搜索了这个问题,但无法弄清楚它!角度可收藏的路线2

这里是我的核心的一些片段:

的index.html

<html> 
    <head> 
    <title>Angular 2 QuickStart</title> 
    <meta charset="UTF-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 

    <!-- 1. Load libraries --> 
    <!-- 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> 
    <script src="node_modules/ng2-bootstrap/bundles/ng2-bootstrap.min.js"></script> 
    <!-- 2. Configure SystemJS --> 
    <script src="systemjs.config.js"></script> 
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
    <script> 
     System.import('app').catch(function(err){ console.error(err); }); 
    </script> 
    <link rel="stylesheet" href="node_modules/dragula/dist/dragula.css"> 
    <base href = ''> 
    </head> 
    <!-- 3. Display the application --> 
    <body> 
    <main-app class='container'>Loading...</main-app> 
    </body> 
</html> 

AppComponent

import { Component } from '@angular/core'; 

@Component({ 
    selector: 'main-app', 
    template: ` 
     <h4>Today: {{ todaysDate | date:"dd/MM/yy"}}</h4> 
     <nav> 
      <a routerLink = '/home' routerLinkActive = 'active'>Home Tab</a> 
      <a routerLink = '/clients' routerLinkActive = 'active'>Clients Tab</a> 
      <a routerLink = '/aboutus' routerLinkActive = 'active'>About Us Tab</a> 
     </nav> 
     <router-outlet></router-outlet> 
    ` 
}) 
export class AppComponent{ 
    .... 
    .... 
} 

AppRouter:

import { Routes, RouterModule } from '@angular/router'; 
import { homeComponent } from '../home.component/home.component'; 
import { clientsComponent } from '../clients.component/clients.component'; 
import { aboutusComponent } from '../aboutus.component/aboutus.component'; 

const routes = [ 
    { 
     path: 'home', 
     component: homeComponent 
    }, 
    { 
     path: 'clients', 
     component: clientsComponent 
    }, 
    { 
     path: 'aboutus', 
     component: aboutusComponent 
    }, 
    { 
     path: '**', 
     component: homeComponent 
    } 
]; 
export const appRouteProviders = []; 
export const appRoutes = RouterModule.forRoot(routes); 

当我试图把一个链接直接在URL,说 - http://localhost:3000/clientshttp://localhost:3000/aboutus,这是行不通的!那么为什么这些链接不可收藏?什么懒惰加载到底做得如何?请帮助我。

+1

听起来像http://stackoverflow.com/questions/31415052/angular-2-0-router-not-working-的DUP重新加载浏览器 –

回答

2

你有此行您的index.html定义

<base href='/' > 
+0

是的,通常它的工作很好,但我无法直接跳转到任何特定的URL。 – Shree

+0

您可以更新您的问题并添加您的index.html代码。 应该解决你的问题。 – 12seconds

+0

是的,我更新了我的问题。 – Shree