当前位置: 首页 > 面试题库 >

$ routeParams Hard Refresh在服务器上不起作用(需要基本标签)

段干瑞
2023-03-14
问题内容

这是我的.htaccess文件:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteRule ^(.*) /index.html [NC,L]

这是app.js

var app = angular.module('router', ['ngRoute']);

app.controller('main', function($scope, $location, $routeParams){
    $scope.test = 'testing';
    $scope.theID = $routeParams.theID;
});

// Routing Configuration
app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
    $routeProvider
        .when('/about', {
            templateUrl: 'views/about.html'
        })
        .when('/paramtest/:theID', {
            templateUrl: 'views/aboutID.html',
            controller: 'main'
        })
        .otherwise({
            templateUrl: 'views/home.html'
        });

        $locationProvider.html5Mode(true);
}]);

这是aboutID.html

ID: {{theID}}

当我转到http://example.com/about它时效果很好,即使我执行了cmd + r刷新,它仍然可以正常加载页面。

如果我从应用程序内单击链接并转到http://example.com/paramtest/1234它,则效果很好。

问题是如果我尝试直接进入http://example.com/paramtest/1234或执行硬刷新http://example.com/paramtest/1234角度路由不再起作用,并且所有变量都像这样输出{{var}}

我也有<base href="/">标签。

-附加文件-

index.html

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Contractors</title>

<link href='http://fonts.googleapis.com/css?family=Quicksand:400,300,700' rel='stylesheet' type='text/css'>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.css" rel="stylesheet" type="text/css">
<link href="styles/datepicker.css" rel="stylesheet" type="text/css">
<link href="style.css" rel="stylesheet" type="text/css">
<link href="styles/classic.date.css" rel="stylesheet" type="text/css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.0.1/dropzone.css" rel="stylesheet" type="text/css">
<link href="js/ng-sortable.min.css" rel="stylesheet" type="text/css">
<link href="js/jquery.fancybox.css" rel="stylesheet" type="text/css">

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="https://cdn.firebase.com/js/client/2.2.2/firebase.js"></script>
<script src="https://cdn.firebase.com/libs/angularfire/1.0.0/angularfire.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular-route.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular-animate.js"></script>

<script type="text/javascript" src="js/angular-datepicker.js"></script>

<script type="text/javascript" src="app.js"></script>

<base href="/">

</head>

<body ng-app="bidder" ng-controller="main" flow-drag-enter="style={border: '5px solid green'}">
    <div class="header" ng-controller="main">
        <div class="logo">
            <a href="/"><img src="images/logo.png"></a>
        </div>
    </div>

    <!-- MAIN CONTENT -->
    <div ng-view ng-controller="main" class="view-animate" ng-if="firebaseUser"></div>

    <div class="profileSection" ng-if="firebaseUser" ng-controller="main">
        <div class="profileTopLeft">
            <img src="thumb.php?w=30&h=30&src=uploads/{{user.profilePicture || noPicture.png}}" ng-if="user.profilePicture" class="profilePicTop"> 
            <i class="fa fa-user" ng-if="!user.profilePicture"></i> 
            <b>{{user.Name}}</b> <small>{{user.Email}}</small>
        </div>
        <div class="profileTopRight">
            <a href="profile"><i class="fa fa-th-list"></i> My Profile</a>
            <a href ng-click="logoutUser()"><i class="fa fa-sign-out"></i> Logout</a>
        </div>
    </div>

    <!-- REGISTRATION -->
    <div ng-if="!firebaseUser" ng-controller="main">
        <loginregister></loginregister>
    </div>

    <div class="clear" style="height: 100px;"></div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>

<script type="text/javascript" src="js/jquery.fancybox.js"></script>
<script type="text/javascript" src="js/jquery.expander.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.0.1/dropzone.js"></script>

</body>
</html>

来自app.js的路由段

// PAGE SETUP
app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
    $routeProvider
        .when('/about', {
            templateUrl: 'views/about.html'
        })
        .when('/findcontractor', {
            templateUrl: 'views/findcontractor.html'
        })
        .when('/editjob/:jobID', {
            templateUrl: 'views/editjob.html'
        })
        .when('/viewcandidates/:jobID/:validate', {
            templateUrl: 'views/viewcandidates.html'
        })
        .when('/messenger/:creatorID/:jobID/:candidateID', {
            templateUrl: 'views/messenger.html'
        })
        .when('/profile', {
            templateUrl: 'views/profile.html'
        })
        .when('/findwork', {
            templateUrl: 'views/findwork.html'
        })
        .otherwise({
            templateUrl: 'views/home.html'
        });

        $locationProvider.html5Mode(true);
}]);

普通的url
http://example.com/about/可以完美地工作,但是任何参数页面都无法进行强制刷新,它会返回404或index.html而不包含任何JavaScript。


问题答案:

如果有人遇到与此类似的问题,请确保您将

<base href="/">

在index.html文件的顶部,标题的正下方。

那就是最终为我解决的问题。



 类似资料:
  • 问题内容: 从我的本地计算机到开发服务器,Web Deploy 3.0可以使用以下命令与Visual Studio 2012发布配置文件配合使用: msbuild。\ myproj.csproj / verbosity:d /p:DeployOnBuild=true;PublishProfile=Develop;VisualStudioVersion=11.0;AllowUntrustedCert

  • 我正在另一台计算机上安装Wamp服务器,以运行一个中型数据库和用户界面。我已经成功拦截了IIS,并将服务器路由到Localhost:8080。但是每当我试图从本地主机主页访问我的项目时,在www文件中;我被重定向到一个页面没有找到错误。 当我将鼠标悬停在链接上方时,目录总是出现“http:// ProjectFolderNameHere /”。当它应该是“http:// LocalHost:808

  • 我在我的Laravel项目中有这个ajax请求(这是一个简单的版本,但它正在工作): 当我在本地工作,我使用PHP工匠服务ajax调用工作,但当我部署到我的正式服没有(因为路径 /admin/lessons/addMember/licenseMemberId不是服务器中的完整路径)。最好的方法应该是走这条路线,但我不知道怎么走。这是路由表: 有没有办法在参数设置中使用laravel路线?如果没有,

  • 应用服务器:IBM Websphere Java 6 问题: 以下是web应用程序的文件夹结构: WEB-INF/库/道具/ 问题是下面的代码不工作: this.getClass(). getResourceAsStream('/props'/fileName),其中fileName是WEB-INF/lib/pros的props文件夹中的有效文件名。 调用上述方法的类位于JAR中,并包含在lib中

  • 当我运行时,一切都很酷,但当Travis运行相同的命令时,我得到的是 警告:未设置“IncludeAntrunTime”,默认值为Build.sysclasspath=Last;对于可重复构建[javac]将12个源文件编译到/home/travis/build/awesometeamplayer/event-receiver/build[javac]注意:/home/travis/build/a

  • 本文向大家介绍在Linux服务器上安装 memcached的基本操作,包括了在Linux服务器上安装 memcached的基本操作的使用技巧和注意事项,需要的朋友参考一下 一、memcached的安装 1、下载 memcached-1.4.33.tar.gz、libevent-2.0.22-stable.tar.gz   安装 memcached 依赖 libevent 2、安装 libevent