Home:ALL Converter>Angular - Routing is not working (MEAN)

Angular - Routing is not working (MEAN)

Ask Time:2018-02-18T03:08:25         Author:Rafineria

Json Formatter

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 {}

Author:Rafineria,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/48844931/angular-routing-is-not-working-mean
yy