Cómo usar rutas secundarias en Angular 2
Versión angular 2: 2.0.0-alpha.44
He estado tratando de enrutar en Angular 2. Aunque pude hacer el enrutamiento normal, estoy enfrentando algunos problemas cuando introduzco rutas secundarias. Aquí está el ejemplo en plnkr (http://plnkr.co/edit/Y5doqU1WcEe4Ldr7KfPJ)
A continuación se muestra el código para una referencia rápida. Estoy tratando de lograr el enrutamiento a continuación
App
/\
/ \
HomeCmp HelloCmp
\
\
ChildCmp
Y a continuación es cómo configuré mis caminos
import {bootstrap, bind, Component, View} from 'angular2/angular2'
import {RouteConfig, RouteParams, ROUTER_DIRECTIVES, APP_BASE_HREF, ROUTER_BINDINGS} from 'angular2/router'
@Component({
selector: 'child-cmp'
})
@View({
template: `
<div>
<h3>Whats up</h3>
</div>
`
})
class ChildCmp { }
// ************************ Hello Component ***********************************
@Component({
selector: 'hello-cmp'
})
@View({
template: `
<div>
<h2>Hello there !</h2>
<router-outlet></router-outlet>
</div>
`,
directives: ROUTER_DIRECTIVES
})
@RouteConfig([
{path: '/', component: ChildCmp, as: 'ChildCmp'}
])
class HelloCmp { }
//************************** HOME Component ***********************************
@Component({
selector: 'home-cmp'
})
@View({
template: `
<div>
<h2>Welcome Home</h2>
</div>
`
})
class HomeCmp {}
//************************* APP Component *************************************
@Component({
selector: 'app-cmp'
})
@View({
template: `
<div>
<h1>Hello {{message}}!</h1>
<a [router-link]="['./HomeCmp']">home</a>
<a [router-link]="['./HelloCmp']">hello</a>
<hr>
<router-outlet></router-outlet>
</div>
`,
directives: ROUTER_DIRECTIVES
})
@RouteConfig([
{path: '/', component: HomeCmp, as: 'HomeCmp'}
{path: '/hello/...', component: HelloCmp, as: 'HelloCmp'}
])
export class App {
message:string = 'world';
}
bootstrap(App, [
ROUTER_BINDINGS,
bind(APP_BASE_HREF).toValue(location.pathname)
]);
Cuando elimino rutas secundarias, funciona bien. Pero con las rutas secundarias me sale el siguiente error.
EXCEPTION: Link "["HelloCmp"]" does not resolve to a terminal or async instruction. in [null]
Seguí el artículo mencionadoaquí. Pero no es capaz de hacerlo funcionar. Puede ayudarme alguien, por favor ? Gracias