Node.js 角2路由器:无法匹配任何路由
尝试在我的浏览器中加载localhost:3000/verifyemail时,我收到错误: 错误:无法匹配任何路由 我已经阅读了关于这一点的其他SO问题,并验证了以下内容: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
- 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';
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';