问题
I'm developing a single page application (SPA) using Sails.js as a backend. All I want is to redirect all routes to a single controller action.
However, when I do the following:
// config/routes.js
module.exports.routes = {
'GET *': 'MainController.application'
};
All requests are getting redirected to my application route, even for static files like CSS/JavaScript, etc. Is there an easy way to fallback to my application route when there is no other means to handle it?
I want:
- All static files to be served directly (JS, CSS, HTML partials)
- All specific routes to be handled as is
- In other case redirect to a single entry-point controller
回答1:
After thorough re-reading of the docs I've found a skipAssets route parameter.
Here's my new configuration:
// config/routes.js
module.exports.routes = {
'GET *': {
controller: 'MainController',
action: 'application',
skipAssets: true
}
};
Looks like it's working as required.
来源:https://stackoverflow.com/questions/32167785/sails-js-single-page-application-spa-redirect-all-missing-unused-routes-to-a