我尝试使用html提供程序实现角度js状态更改。但是当我尝试刷新页面时页面显示404错误。问题是什么。 ?
我的州提供者是
$stateProvider
.state('home', {
url: '/Edu',
views: {
'content@': {
templateUrl: 'dashboard.html',
controller: 'dashCtrl'
}
},
params: {'registerData' : ''}
})
.state('dash_home', {
url: '/dash_home',
views: {
'content@': {
templateUrl: 'dash_home.html',
controller: 'dashCtrl'
}
},
params: {'registerData' : ''}
})
.state('login', {
url: '/login',
views: {
'content@': {
templateUrl: 'login.html',
controller: 'dashCtrl'
}
},
params: {'registerData' : ''}
});
html5 conf是,
app.config(function($locationProvider) {
$locationProvider.html5Mode(false);
});
并且还放
<base href="/">
在html页面中。但它没有用。
修改
server {
listen 80 ;
listen [::]:80 ;
root /var/www/Edu;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
root /var/www/Edu;
try_files $uri /index.html;
}
}
答案 0 :(得分:0)
当网址错误或没有状态时,您可以使用默认重定向(只需将$ urlRouterProvider注入配置功能)。
添加&#39; /&#39;声明重定向到您的家庭&#39;页面,像这样:
.state('/', {
url: '/Edu',
views: {
'content@': {
templateUrl: 'dashboard.html',
controller: 'dashCtrl'
}
},
params: {'registerData' : ''}
})
添加默认重定向,如下所示:
$urlRouterProvider.otherwise('home');
希望这有助于好运。