在删除哈希标志之前,我有
mainApp.config(function ($locationProvider, $routeProvider) {
$routeProvider
.when('/page', {
controller: 'Page',
templateUrl: 'templates/page.html'
})
.when('/main', {
controller: 'Main',
templateUrl: 'templates/main.html'
})
.otherwise({ redirectTo: '/main'});
//$locationProvider.html5Mode(true);
});
Run Code Online (Sandbox Code Playgroud)
这些都很好
http://localhost:8080/index.html#/main
http://localhost:8080/index.html#/page
Run Code Online (Sandbox Code Playgroud)
删除井号后,我添加到index.html
<base href="/">
Run Code Online (Sandbox Code Playgroud)
<script src="/vendor/bootstrap-dist/js/bootstrap.min.js"></script>
<script src="/vendor/javascript/angular/angular.js"></script>
<script src="/vendor/javascript/angular/angular-route.js"></script>
<script src="/vendor/javascript/angular/ui-bootstrap-tpls-0.11.2.min.js"></script>
<script src="/javascript/index.js"></script>
<script src="/javascript/controllers/main.js"></script>
<script src="/javascript/controllers/page.js"></script>
Run Code Online (Sandbox Code Playgroud)
和index.js
$locationProvider.html5Mode(true);
Run Code Online (Sandbox Code Playgroud)
现在点击http://localhost:8080重定向到http://localhost:8080/main
但http://localhost:8080/main直接在浏览器中返回404和其他页面
我该怎么做才能解决这个问题?
我的后端是java
这是预期的.这是html5未打开时发生的情况:
http://localhost:8080/index.html#/main在地址栏输入网址现在启用html5模式并加载index.hml会发生什么?
http://localhost:8080/index.html在地址栏输入网址现在,如果您点击刷新或直接输入http://localhost:8080/main地址栏会发生什么?那么在这种情况下,你说浏览器:"请在网址加载页面http://localhost:8080/main.这就是浏览器的作用:它发送一个HTTP请求http://localhost:8080/main.由于服务器在这个地址没有任何东西,它会发回一个404.
现在如何使它工作?它实际上非常简单:您需要配置服务器以在获取路径请求时/main(以及角度应用程序的所有其他路径)发送回index.html页面.这样,浏览器将加载HTML页面,它包含的角度应用程序将重新启动,角度路由器将从/mainURL 解析path(),因此它将加载视图和与该路径关联的控制器.
| 归档时间: |
|
| 查看次数: |
1287 次 |
| 最近记录: |