您好,我在使用 angular.js 路由路径时遇到了一点问题。我在下面解释我的代码。
app.js:
var GoFastoApp=angular.module('GofastoHome',['ngRoute']);
GoFastoApp.config(function($routeProvider) {
$routeProvider
.when('/',{
templateUrl : 'view/home.html',
controller : 'homecontroller'
})
.when('/deptinfo',{
templateUrl : 'view/info.html',
controller : 'infocontroller'
})
.when('/TimeTable',{
templateUrl : 'view/time.html',
controller : 'timecontroller'
})
.when('/course',{
templateUrl : 'view/course.html',
controller : 'coursecontroller'
})
.when('/subject',{
templateUrl : 'view/subject.html',
controller : 'subjectcontroller'
})
.when('/hod',{
templateUrl : 'view/hod.html',
controller : 'hodcontroller'
})
.when('/faculty',{
templateUrl : 'view/faculty.html',
controller : 'facultycontroller'
})
})
当我在浏览器的地址栏上输入网址oditek.in/Gofast/
时,所需的页面就会出现,但在获取页面后,地址栏网址显示oditek。 in/Gofast/#/
。在这里,我收到了此网址中不需要的 #
,需要将其删除。请帮助我解决此问题。
最佳答案
您需要启用html5Mode
并指定 <base>
标记中的 URL 值如下所示。
app.js
GoFastoApp.config(function($routeProvider, $locationProvider) {
$locationProvider.html5Mode({
enabled: true,
requireBase: true
});
// remaining router config goes here
});
通常最好有 <base>
在你的<head>
里面,但是如果您有 <head>
之外的 CSS 和 JS 文件,然后将其添加到 HTML 页面的底部,可能位于所有 CSS 和 JS 文件之后,然后关闭 <body>
,定义如下的baseURI。
<base href="/Gofast/">
关于javascript - 使用 angular.js 路由路径时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32886891/