Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.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
Node.js 角2路由器:无法匹配任何路由_Node.js_Angular_Angular2 Routing - Fatal编程技术网

Node.js 角2路由器:无法匹配任何路由

Node.js 角2路由器:无法匹配任何路由,node.js,angular,angular2-routing,Node.js,Angular,Angular2 Routing,尝试在我的浏览器中加载localhost:3000/verifyemail时,我收到错误: 错误:无法匹配任何路由 我已经阅读了关于这一点的其他SO问题,并验证了以下内容: Angular2:2.3.1默认使用路径定位策略,我没有更改它。我不喜欢使用哈希定位策略 我已经为HTML5 pushState配置了我的Nodejs服务器(server.js在下面) 我在我的index.html中的顶部有 我设置了默认和捕获所有路由 const appRoutes: Routes = [ { pa

尝试在我的浏览器中加载localhost:3000/verifyemail时,我收到错误:

错误:无法匹配任何路由

我已经阅读了关于这一点的其他SO问题,并验证了以下内容:

  • Angular2:2.3.1默认使用路径定位策略,我没有更改它。我不喜欢使用哈希定位策略
  • 我已经为HTML5 pushState配置了我的Nodejs服务器(server.js在下面)

  • 我在我的index.html中的
    顶部有

  • 我设置了默认和捕获所有路由

    const appRoutes: Routes = [
      { path: 'home',
        outlet: 'full-page',
        component: DefaultLandingPageComponent
      },
    
      { path: 'verifyemail',
        outlet: 'full-page',
        component: EmailVerificationComponent
      },
    
      { path: '',
        redirectTo: '/home',
        pathMatch: 'full'
      },
    
      { path: '**',
        outlet: 'full-page',
        component: DefaultLandingPageComponent
      }
     ];
    
  • 我已将路由器模块导入到app.module.ts中,并在app.component.html文件中包含一个路由器出口

    //in app.module.ts:
    @NgModule({
      ...
      imports: [
        ...
        RouterModule.forRoot(appRoutes)
      ]
      ...
      });
    
    //in app.component.html
    import { RouterModule, Routes } from '@angular/router';
    
非常感谢能帮我的人

更新1 我已经删除了routes和路由器出口的所有名称,这要感谢Günter Zöchbauer在下面评论中的观察

更新2 在localhost:4200/verifyemail上,一切都按预期运行,它通过
ng serve
运行。
使用localhost:3000/verifyemail时,问题仍然存在,它通过
节点服务器.js运行

每个路由都需要一个路由,该路由将组件添加到未命名的出口。
命名插座只能在未命名插座之外使用,不能代替。

非常感谢您的帮助-这可能是个问题,但它仍然不起作用。我从路由和路由器出口中删除了name属性,现在它的内容是
。服务器重新加载正在工作-如果我将res.sendFile更改为index.html以外的任何其他文件,它将正常工作。问题是当它重定向到index.html,然后找不到任何RoutesOrry,无法帮助您设置node.js服务器。谢谢-服务器似乎工作正常,所以我认为问题出在角度方面。我的角度代码中还有什么东西可能是个问题吗?感谢您的帮助如果您使用
RouterModule.forRoot(appRoutes,{useHash:true})
但仍然不起作用,那么这是一个角度代码问题,否则这是一个服务器问题。看起来我们当时有一个角度问题-我将
RouterModule.forRoot(appRoutes)
替换为
RouterModule.forRoot(appRoutes,{useHash:true})
我收到了相同的错误
//in app.module.ts:
@NgModule({
  ...
  imports: [
    ...
    RouterModule.forRoot(appRoutes)
  ]
  ...
  });

//in app.component.html
import { RouterModule, Routes } from '@angular/router';