问题描述:

so with the latest angular 2 we had to remove all prefixed forward slashes in routes and I am not sure if this is because of it or a new feature, but now with ng2 0.7 the index.html is removed from the URL path...

so before a route would look like:

http://localhost:8080/src/public/index.html/App1/Dashboard

but now routes look like

http://localhost:8080/src/public/App1/Dashboard

and so the problem is that if I want to reload a server (any server) and go directly to this page /App1/Dashboard my server gives a 404 error

so the question is, how do we configure now a local node server, or maybe the solution as at the router level, so we can jump directly into a page... as again, because the router now removes the index.html prefix in the url it just ends up being 404 error

regards

Sean

网友答案:

Example of node server?

    import * as express from 'express';
    import {ng2engine} from 'angular2-universal-preview';

    // Angular 2
    import {App} from './src/app';

    let app = express();

    // Express View
    app.engine('.ng2.html', ng2engine);
    app.set('views', __dirname);
    app.set('view engine', 'ng2.html');


    // static files
    app.use(express.static(__dirname));


    app.use('/', (req, res) => {
      res.render('index', { App });
    });



    app.listen(3000, () => {
      console.log('Listen on http://localhost:3000');
    });
相关阅读:
Top