Page not found when updating on SailsJS

I am creating a sailing application and I am using it with angularjs. My problem is that every time I refresh the page the page with which was not found. In apache, I can fix this with this htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)       /index.php/#/$1 
</IfModule>

How can I realize this on sail

+2
source share
2 answers

I found that there are two ways to do this.

Single entry point

This method is much easier to maintain, but it may not work for everyone. If you have several applications with angular functions, you will have to use the second method or a hybrid approach.

, , , :

config/routes.js :

//wildcard catchall for angularjs entrypoint.
'/app/*': 'AngularController.index',

angularJS app.js, :

.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
    $routeProvider.when('/app/user', {templateUrl: '/angular/application/views/settings/user.html', controller: 'settingsUserCtrl'});
    $routeProvider.when('/app/tags/:tagId', {
        templateUrl: '/angular/application/views/tags/tag.html',
        controller: 'tagListCtrl',
        reloadOnSearch: true
    });
    $routeProvider.otherwise({redirectTo: '/app/user'});
    ...
}])

, /app/anything. AngularJS, AngularJS ngRoute .

/

config/routes.js , Sails Controllers, / AngularJS

'/user/*': 'UserController.index',
'/tag/*': 'TagController.index',

angular app.js

.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
    $routeProvider.when('/user', {templateUrl: '/angular/application/views/settings/user.html', controller: 'settingsUserCtrl'});
    $routeProvider.when('/tags/:tagId', {
        templateUrl: '/angular/application/views/tags/tag.html',
        controller: 'tagListCtrl',
        reloadOnSearch: true
    });
    $routeProvider.otherwise({redirectTo: '/app/user'});
    ...
}])
-2

, Sails mod_rewrite, .

0

Source: https://habr.com/ru/post/1547631/


All Articles