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?
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
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
Sunucu tarafında rota yapılandırılmış mı? değilse, işe yaramaz. Şimdi işe yaraması için HashLocationStrategy ile gitmelisin. – micronyks
@micronyks Peki benim ekspres kurulumdan bir alıntı olan son snippet'i aldım, bu yüzden bunu yapması gerektiğini düşündüm? –
HashLocationStrategy ile çalıştınız mı? – micronyks