Currently in the process of adjusting an existing angular application to integrate with the format of this Starter Project. Within my app module, there exists a submodule (tutorial) structured as follows:
https://i.sstatic.net/Q9Dku.png Upon initially accessing the root domain and navigating through router links to
http://localhost:3000/tutorial/chapter/0
, everything functions properly. However, upon refreshing the page or attempting to directly access that link, an error occurs:
Unhandled Promise rejection: Template parse errors:
'my-app' is not a known element:
1. If 'my-app' is an Angular component, verify it's part of this module.
2. If 'my-app' is a Web Component, add "CUSTOM_ELEMENTS_SCHEMA" to '@NgModule.schema' of this component to suppress this message. ("<body>
[ERROR ->]<my-app>
<div class="valign-wrapper">
<div class="preloader-wrapper active valign") a@30:4 ; Zone: <root> ; Task: Promise.then ; Value: Error: Template parse errors:(…) Error: Template parse
This issue seems to arise because instead of linking to the appcomponent with the tutorial submodule as a child, the URL directs to TutorialModule, causing the <my-app></my-app>
tags from index.html
to go unrecognized. This previously worked, so it's unclear what aspect of this new configuration has triggered the problem.
Shown below is my app.routes.ts
:
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);
and my tutorial.routes.ts
:
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);
Lastly, within my app.ts
where I establish the express routes, the following is present:
app.all(/^\/tutorial$/, (req, res) => {
res.redirect('/tutorial/');
});
app.use('/tutorial/', (req, res) => {
res.sendFile(resolve(__dirname, '../public/index.html'));
});
To serve the angular index for the tutorial component.
The complete repository can be found here