B
B
Boogie19892016-06-25 00:24:14
Angular
Boogie1989, 2016-06-25 00:24:14

How to properly use routing in Express + Angular to serve files?

I use this variant of routes for the admin panel

app.get('/admin/:folder/:file', function(req, res) {
      res.sendFile(__dirname+'/admin/' + req.params.folder + '/' + req.params.file.replace('.map',''));
    });
  app.get('/admin/*', function(req, res) {
      res.sendFile(__dirname+'/admin/index.html');
    });

Everything works fine, but there is one minus, in Angular I cannot use routes with two slashes like admin/admin/admin, because when I reload the page, Express says that there is no such file. How to deal with this problem or how do you make routes?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_ _, 2016-06-25
@AMar4enko

Dump all server routes (that serve data from the server) into a separate subset, like /admin/files/:folder/:file
On the client, don't use routes starting with /admin/files

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question