Angular 2 router refresh page during routing

I am trying to set up a simple route while learning Angular 2, whenever I click on the link, the browser is redirected to the new route, but the browser asks for all the resources (does not behave like a one-page application).

my index file

<!--... . .  various scripts and styles . . . . . --->
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="node_modules/angular2/bundles/router.dev.js"></script>
<script src="node_modules/angular2/bundles/http.dev.js"></script>

<script>
  System.config({
    packages: {        
      app: {
        format: 'register',
        defaultExtension: 'js'
      }
    }
  });
  System.import('app/main')
        .then(null, console.error.bind(console));
</script>
</head>
<body>
  <app></app>
</body>

application sources

main.ts

import {bootstrap}    from 'angular2/platform/browser';
import {RoutingApp} from './routing/routing.app'
import {ROUTER_PROVIDERS} from 'angular2/router'

bootstrap(RoutingApp, [ROUTER_PROVIDERS]);

Routingapp

import {Component} from "angular2/core"
import {RouteComponent} from './route.component'
import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from 'angular2/router';


@Component({
    selector : 'app',
    template :  `
        go to this <a href="/link">link</a>
        <br />
        <router-outlet></router-outlet>

    `,
    directives: [ROUTER_DIRECTIVES],
    providers: [ROUTER_PROVIDERS]
})
@RouteConfig([
    {path: '/link', name: 'Link', component: RouteComponent}
])
export class RoutingApp{

}

and RouteComponent

import {Component} from 'angular2/core'

@Component({
    template: `
        hello from RouteComponent
    `
})
export class RouteComponent{}

what am I doing wrong? Angular version 2.0.0-beta.7.

Thank you for your understanding.

+4
source share
1 answer

You must use the directive routerLinkto go to the route:

<a [routerLink]="['Link']">link</a>

, ROUTER_DIRECTIVES directives

+7

All Articles