问题
I'm working on my first Angular app and I have a problem with routing, because app response with "Cannot GET /(url)" errors. Console logs are empty, so after reading many similar topics I suspect issue with server.js:
var express = require('express');
var bodyParser = require('body-parser');
var path = require('path');
var http = require('http');
var app = express();
var api = require('./server/api.js');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(express.static(path.join(__dirname, 'dist')));
app.use('/', api);
app.get('*'), (req, res) => {
res.sendFile(path.join(__dirname, 'dist/index.html'));
}
var port = process.env.PORT || '3000';
app.set('port', port);
var server = http.createServer(app);
server.listen(port, () => console.log("Server is running"));
In my index.html I have:
<base href="/">
so this is not source of the problem. Angular routing code is good, I've tested it on other app. I would grateful for some help.
app-routing.module:
import {NgModule} from "@angular/core";
import {RouterModule, Route} from "@angular/router";
import {Pgee2017StatsComponent} from "./pgee2017/pgee2017-stats/pgee2017-stats.component";
const APP_ROUTES : Route[] = [
{ path: 'pgee17', component: Pgee2017StatsComponent}
];
@NgModule({
imports: [
RouterModule.forRoot(APP_ROUTES)
],
exports: [
RouterModule
]
})
export class AppRoutingModule {}
来源:https://stackoverflow.com/questions/48844931/angular-routing-is-not-working-mean