Issue 1:
I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

Given a module using the RouterModule:

@NgModule({
declarations: [
AppComponent,
UsersComponent,
UserComponent,
HomeComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
RouterModule.forRoot([
{ path: '', component: HomeComponent},
{ path: 'users', component: UsersComponent}
])
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }

UsersComponent uses UserComponent and a RouterLink in its template:

<app-user></app-user>
<a routerLink="/">Home</a>

whereas UserComponent is just plain HTML for this repro.

Testing a simple component using Angular 2.1.0 and Router ~3.0.0

for a component using routerLink in its template like UsersComponent, we had to add RouterTestingModule in the imports of the testing module:

import { TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { AppModule } from '../app.module';
import { UsersComponent } from './users.component';

describe('Component: Users', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppModule, RouterTestingModule],
});
});

it('should create the component', () => {
let fixture = TestBed.createComponent(UsersComponent);
let app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
});
});

whereas for a "dumb" component like UserComponent we did not:

import { TestBed } from '@angular/core/testing';
import { AppModule } from '../app.module';
import { UserComponent } from './user.component';

describe('Component: User', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppModule],
});
});

it('should create the component', () => {
let fixture = TestBed.createComponent(UserComponent);
let app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
});
});

Now, using the router 3.1.0, the above test throws:

No base href set. Please provide a value for the APP_BASE_HREF token or add a base element to the document.

This can be fixed by adding the RouterTestingModule in the imports of the testing module for the dumb component too, but this is a regression/breaking change compared to the behavior we used to have.

Expected behavior

We should be able to test a component that does not rely on routerLink without having to import the RouterTestingModule as we used to.

Minimal reproduction of the problem with instructions

See above

Please tell us about your environment:

MacOSX

Angular version: 2.0.X

Angular 2.1.0, Router 3.1.0

Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]

All

Language: [all | TypeScript X.X | ES6/7 | ES5]

All

Node (for AoT issues): node --version =

Issue 2:
I'm submitting a ...

bug report

Current behavior

Angular may be performing unnecessary duplicate work when starting up the app. I would expect that the first time that a component is encountered that it's "compiled" (the template string parsed and the JS code generated) and after that it's re-used if and when the component is encountered again.

But if you use templateUrl you will see the same template file being requested over and over which suggests this may not be the case. For example, I have a price display component which is used in multiple places and the template can be requested 8+ times or more. Is it being re-parsed and re-built each time?

It seems unnecessary and wasteful.

Expected/desired behavior

Any templateUrl should be requested no more than once.

What is the expected behavior?

Still only request the templateUrl once (erm, maybe the issue template doesn't need this same heading repeated?)

What is the motivation / use case for changing the behavior?

Optimize behavior

Angular version: 2.0.0-beta.X

2.0.0-RC-1