Sails.js Single Page Application (SPA) — redirect all missing/unused routes to a single controller action

你离开我真会死。 提交于 2019-12-10 19:36:08

问题


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:

  1. All static files to be served directly (JS, CSS, HTML partials)
  2. All specific routes to be handled as is
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!