1
当试图加载本地主机:在浏览器中3000/verifyemail,我收到错误:角2路由器:不能匹配任何路由
Error: Cannot match any routes
我已经通过这个其他的做题阅读,并有验证以下内容:
- Angular2:2.3.1默认使用路径位置策略,但我没有更改它。我不喜欢使用哈希定位策略
我已经配置了我的NodeJS服务器HTML5 pushState的(server.js低于)
// Parsers for POST data app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); // Point static path to dist app.use(express.static(path.join(__dirname, 'dist'))); // Get API routes const api = require('./src/server/routes/api.js'); // Set api routes app.use('/api', api); // Catch all other routes and return the index file app.get('*', (req, res) => { res.sendFile(path.join(__dirname, 'dist/index.html')); }); const port = process.env.PORT || '3000'; app.set('port', port); const server = http.createServer(app); server.listen(port,() => console.log(`API running on localhost:${port}`));
我
<base href="/">
在我的<head>
在我的索引上。 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 我已经移除路线冈特Zöchbauer的观察所有名称和路由器的出口,由于在评论下方
更新2 一切工作在本地主机上预期:4200/verifyemail ,它通过ng serve
运行。 当使用本地主机:3000/verifyemail时,问题仍然存在,该主机通过node server.js
运行
非常感谢您的帮助 - 这可能是一个问题,但它仍然无法正常工作。我从路由和路由器插座中删除了名称属性,路由器插座现在读取' router-outlet>'。服务器重新加载正在工作 - 如果我将res.sendFile更改为除index.html之外的任何其他文件,它将正确执行。问题是,当它获取重定向到index.html,然后找不到任何路由 –
ManGI1
对不起,不能帮助您与node.js服务器设置。 –
谢谢 - 服务器似乎工作正常,所以我认为问题在于角度。我的角码中的其他内容是否可能会成为问题?感谢您的帮助 – ManGI1