Refresh specific page with Angular, Express and Jade (using html5mode)

后端 未结 2 902
忘掉有多难
忘掉有多难 2021-01-12 22:27

I\'m trying to refresh a page and execute client route to open a template inside ng-view

Index.jade

extends layouts/default

block c         


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-12 23:06

    You're using HTML5 routes with a hashbang fallback. What that means is you want to set your server up so that requests to /cameras/12 redirect to /#!/cameras/12. The server will then render your Angular application, which will detect that it wants to go to your viewCamera state and will rewrite the url on the client.

    You can accomplish this by simply adding the following middleware to your express app:

    app.use(function (req, res, next) {
        res.set('Location', '/#!' + req.path)
           .status(301)
           .send();
    });
    

提交回复
热议问题