在使用angular.js路由路径时遇到问题

Getting issue while routing the path using angular.js

本文关键字:路径 遇到 问题 路由 js angular      更新时间:2023-09-26

嗨,在使用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'
    })
})

当我在浏览器的地址栏上输入url oditek.in/Gofast/时,所需的页面即将到来,但在获得页面后,地址栏url显示oditek.in/Gofast/#/。在这里,我使用此url获得不需要的#,需要删除此。请帮我解决这个问题。

您需要启用html5Mode并在标记中指定<base> URL值,如下所示。

app.js

GoFastoApp.config(function($routeProvider, $locationProvider) {
    $locationProvider.html5Mode({
      enabled: true,
      requireBase: true
    });
   // remaining router config goes here
});

通常在你的<head>里面有<base>,但是如果你有CSS &在<head>之外的JS文件,然后将其添加到HTML页面的底部,可能在所有CSS和JS文件之后,在关闭<body>之前,像下面这样定义baseURI。

<base href="/Gofast/">