【发布时间】:2017-07-17 19:00:49
【问题描述】:
这应该很简单。 目标是删除 url 中的 # 。为此,我使用 $locationProvider.html5Mode(true);。但这会在子状态下中断重新加载。
我正在使用 AngularJS 1.6.4 和 ui-router 1.0.0。
我不是在寻找后端的任何东西。 我只是使用 Grunt 来提供应用程序。我不需要配置任何后端来做任何事情。它需要是一个前端修复。要么在 ui-router 中,要么在 Gruntfile 中。
index.html 当然有 base href="/" 集。
routes.module.js '使用严格';
/**
* @ngdoc function
* @name app.module:app.routes
* @description
* # app.routes
* Rollup module for routes and config for parent route
*/
angular
.module( 'app.routes', [
'ui.router'
])
.config( routesConfig );
function routesConfig( $stateProvider, $urlRouterProvider, $locationProvider ) {
$locationProvider.html5Mode(true); // this breaks the refreshing
$urlRouterProvider.otherwise( '/' );
$stateProvider
.state( 'main', {
url : '',
component : 'main',
abstract : true,
})
.state( 'main.home', {
url : '/',
component : 'home',
})
.state( 'main.admin', {
url : '/admin',
component : 'admin',
});
}
我刚刚得到了默认的 Gruntfile.js,这里是连接任务:
connect : {
options : {
port : 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname : 'localhost',
livereload : 35729
},
livereload : {
options : {
open : true,
middleware : function( connect ) {
return [
connect.static( '.tmp' ),
connect().use(
'/bower_components',
connect.static( './bower_components' )
),
connect().use(
'/app/styles',
connect.static( './app/styles' )
),
connect.static( appConfig.app )
];
}
}
},
【问题讨论】:
标签: angularjs html gruntjs angular-ui-router state