【发布时间】:2018-05-11 02:38:48
【问题描述】:
我在 linux 环境中使用 node js (Sails) 作为后端,使用 angularJs 作为前端,在生产模式下使用 nginx 构建独立 Web。我想在我的网址中删除哈希 (#!)。 我按照本教程进行操作
现在,只要我不刷新,我的网站在每个页面中都可以正常运行,而没有哈希 (#!),但是当我刷新时,它会从后端调用我的 API 或找不到 404。我按照那些教程把
<base href="/"/>
在我的 layout.ejs 上,但它仍然无法正常工作。
这是我使用状态路由 angularjs 的示例代码
(function() {
'use strict';
angular
.module('buyer.routes', ['ui.router'])
.config(function($locationProvider, $urlMatcherFactoryProvider, $urlRouterProvider, $stateProvider){
$urlRouterProvider.otherwise("/");
$urlMatcherFactoryProvider.caseInsensitive(true);
$stateProvider
.state('home', {
url: '/',
templateUrl: 'templates/buyer/buyer-index.html',
controller: 'BuyerController',
controllerAs: 'vm'
})
.state('home.testi', {
url: 'testimoni',
templateUrl: 'templates/buyer/buyer-testimoni.html',
controller: 'BuyerTestimoniController',
controllerAs: 'vm',
data : { pageTitle: 'Testimoni page'}
})
$locationProvider.hashPrefix('');
$locationProvider.html5Mode(true);
})
}());
我的代码有什么问题? 谢谢你
【问题讨论】:
标签: javascript angularjs sails.js