2016-09-23 27 views
5

Mevcut bir açısal uygulamayı bu Starter Project yapısına sığacak şekilde değiştirmeye çalışıyorum. Her neyse, bu yüzden uygulama modülümü bir alt modüle (öğretici) sahip. Hangi şuna benzer:Angular2.0 yönlendirici, modül olmayan bileşenler için çalışıyor mu?

enter image description here kök etki alanında iniş ve sonra http://localhost:3000/tutorial/chapter/0 için yönlendirici bağlantıları ile gezinme, her şey gayet iyi çalışıyor. Ben sayfayı yenileyin veya bu bağlantı doğrudan gitmek için çalışırsanız, ancak ben hata alıyorum:

Unhandled Promise rejection: Template parse errors: 
'my-app' is not a known element: 
1. If 'my-app' is an Angular component, then verify that it is part of this module. 
2. If 'my-app' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schema' of this component to suppress this message. (" 

<body> 
    [ERROR ->]<my-app> 
     <div class="valign-wrapper"> 
      <div class="preloader-wrapper active valign"): [email protected]:4 ; Zone: <root> ; Task: Promise.then ; Value: Error: Template parse errors:(…) Error: Template parse 

yüzden bu oluyor inandığı için oldukça o Url'de olarak öğretici altmodülün ile appcomponent bağlantı daha Çocuk, sadece TutorialModule'a bağlanıyor ve index.html'dan <my-app></my-app> etiketi tanınmadı. Bu daha önce çalıştı, bu yüzden bu yeni yapılandırmanın hangi yönünün bunu kırdığından emin değilim.

import { homeComponent } from './components/home/home.component'; 
import { pluginsComponent } from './components/plugins/plugins.component'; 
import { Routes, RouterModule } from '@angular/router'; 

const appRoutes: Routes = [ 
    { path: '', component: homeComponent }, 
    { path: 'tutorial', loadChildren: 'tutorial/tutorial.module', pathMatch: 'prefix'}, 
    { path: 'plugins', component: pluginsComponent } 
]; 

export const appRoutingProviders: any[] = []; 

export const routing = RouterModule.forRoot(appRoutes); 

ve benim tutorial.routes.ts: Burada

benim app.routes.ts olduğunu

nihayet
import { Routes, RouterModule } from '@angular/router'; 

import { tutorialComponent } from './tutorial.component'; 
import { chapterComponent } from './chapter/chapter.component'; 

const tutorialRoutes: Routes = [ 
    { 
    path: 'tutorial', 
    component: tutorialComponent, 
    children: [ 
     { path: 'chapter/:id', component: chapterComponent }, 
     { path: '', redirectTo: 'chapter/0', pathMatch: 'full'}, 
    ] 
    } 
]; 

export const tutorialRouting = RouterModule.forChild(tutorialRoutes); 

benim app.ts Ben ekspres yolları tanımlamak nerede var:

app.all(/^\/tutorial$/, (req, res) => { 
    res.redirect('/tutorial/'); 
}); 
app.use('/tutorial/', (req, res) => { 
    res.sendFile(resolve(__dirname, '../public/index.html')); 
}); 

hizmet etmek öğretici bileşen için açısal dizin.

bütün repo here

+0

Sunucu tarafında rota yapılandırılmış mı? değilse, işe yaramaz. Şimdi işe yaraması için HashLocationStrategy ile gitmelisin. – micronyks

+0

@micronyks Peki benim ekspres kurulumdan bir alıntı olan son snippet'i aldım, bu yüzden bunu yapması gerektiğini düşündüm? –

+0

HashLocationStrategy ile çalıştınız mı? – micronyks

cevap

2

Sorunum <base href="."> nerede <base href="/"> olmalıydı vardı index.html dosya oldu. Bir hata raporum var here

0

@micronyks zaten açıklamada bu sözü ama index.html sayfasına tüm istekleri yönlendirmek için bir setup web sunucusu yapmanız gerekenler. Ardından, uygulamanız yüklenecek ve "derin" bağlantınıza gidecektir.

+0

numaralı belgede aynı bileşenlerle çalışan varsayılan stratejiyi kullanmak istiyorum. Evet biliyorum ve ekspres yolum bunu yapıyor. Sorun, index.html sunulduktan sonra, “uygulamam” - app.component seçicisinin tanınmaması gibi görünüyor. Bu bir modül bileşenidir, sanki bir çocuk bileşeni ile aynı şeyi yapıyormuşum gibi, her şey iyi çalışıyor –

İlgili konular