Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Express Angular2.0路由器适用于组件而非模块?_Express_Angular_Typescript_Angular2 Routing - Fatal编程技术网

Express Angular2.0路由器适用于组件而非模块?

Express Angular2.0路由器适用于组件而非模块?,express,angular,typescript,angular2-routing,Express,Angular,Typescript,Angular2 Routing,我正在尝试修改现有的angular应用程序,以适应此应用程序的结构。无论如何,我有我的应用程序模块和一个子模块(教程)。看起来是这样的: 登陆根域,然后使用路由器链接导航到http://localhost:3000/tutorial/chapter/0,一切正常。但是,如果我刷新页面或尝试直接转到该链接,则会出现以下错误: Unhandled Promise rejection: Template parse errors: 'my-app' is not a known element: 1

我正在尝试修改现有的angular应用程序,以适应此应用程序的结构。无论如何,我有我的应用程序模块和一个子模块(教程)。看起来是这样的:

登陆根域,然后使用路由器链接导航到
http://localhost:3000/tutorial/chapter/0
,一切正常。但是,如果我刷新页面或尝试直接转到该链接,则会出现以下错误:

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"): a@30:4 ; Zone: <root> ; Task: Promise.then ; Value: Error: Template parse errors:(…) Error: Template parse
和我的
教程.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);
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);
最后,在我的
app.ts
中,我定义了我拥有的快速路线:

app.all(/^\/tutorial$/, (req, res) => {
  res.redirect('/tutorial/');
});
app.use('/tutorial/', (req, res) => {
  res.sendFile(resolve(__dirname, '../public/index.html'));
});
为教程组件提供角度索引


整个回购协议都是

@micronyks在评论中已经说过这一点,但您需要做的是设置web服务器,将所有请求重定向到index.html页面。然后你的应用程序将加载并导航到你的“deep”链接。

问题是index.html文件,我有
它应该在哪里
。我有一个错误报告

您是否配置了服务器端路由?否则,它将无法工作。现在,要使其工作,您必须使用HashLocationStrategy。@micronyks我有最后一个片段,它是从我的express设置中摘录的,所以我认为应该这样做?您尝试过HashLocationStrategy吗?@micronyks我想使用默认策略,它与我原来项目中的相同组件一起工作是的,我知道,我想我的快速路线就是这样。问题似乎是一旦提供index.html,
my app
——app.component的选择器就无法识别。我认为这是一个模块的事情,就像我对一个子组件做完全相同的事情一样,一切都很好