【发布时间】:2015-07-11 05:52:01
【问题描述】:
是否可以通过直接从 url 提供 id 来不从 url 提供 # 符号来显示记录?
我正在开发一个网站,其中只有一个查看页面为Login.html。
我需要通过将 url 中的用户 id 作为abc.in/1 来访问它,这里 1 是用户的 id。我将 Login.html 设置为默认页面,当我尝试通过提供 abc.in/1 来访问它时,即url中的id不能显示记录。但是当我给abc.in#/1 时,它会正确显示记录。我不想通过在 url 中提供 # 来访问它。
我的代码如下-
<html ng-app="myApp" style="height: 500px; overflow: auto;">
<head>
<meta charset="utf-8">
<base href="/">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title style="color: white;">c60</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<script src="../app/js/controllers/LoginController.js"></script>
</head>
<body>
---record details
</body>
</html>
在 app.js-
angular.module('myApp', [
'ngRoute', 'ngResource', 'ngCookies',
'myApp.filters',
'myApp.services',
'myApp.directives',
'myApp.controllers',
'ui.bootstrap', 'ngAnimate', 'ngDragDrop' //'ngSanitize',
]).
config(['$routeProvider','$locationProvider', function ($routeProvider,$locationProvider) {
$routeProvider.when('/:id',
{
templateUrl: '/Login.html',
controller: 'LoginController'
});
$routeProvider.otherwise({ redirectTo: '' });
//check browser support
if (window.history && window.history.pushState) {
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
}
}])
如何做到这一点?我只是不想在 url 中给出 # 来显示 url 中提供的特定 id 的记录。我需要一个干净的 url。如何做到这一点?
我尝试使用以下问题Removing the # symbol from angular.js urls 中的提示从我的 ulrs 中删除 # 。现在,问题是如果我尝试直接访问它们,我的 url 将不起作用。从相关问题中的给定示例中,如果将下面的 url 直接放在浏览器 http://localhost/phones 中;就我而言,它是abc.in/1
我会收到 404 错误。知道如何解决这个问题吗?
【问题讨论】:
标签: angularjs html url url-routing angularjs-routing