第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

HTML5模式下的AngularJS路由404錯誤

HTML5模式下的AngularJS路由404錯誤

FFIVE 2019-09-27 15:56:36
我剛開始使用angular js,我嘗試了路由并且工作得很好。問題是當(dāng)我刷新頁面時它顯示404錯誤,因為它正在檢查我的實際目錄而不是在檢查路由。這是完整的代碼<!DOCTYPE html><html><script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.js"></script><body ng-app="myApp">  <base href="/" />  <a href="blue">blue</a>  <a href="green">green</a> //blue.html and green.html are in same directory as index.html  <p>Click on the links to load blue or green.</p>  <div ng-view></div>  <script>    var app = angular.module("myApp", ["ngRoute"]);    app.config(function($routeProvider, $locationProvider) {      $routeProvider        .when("/blue/:name?", {          templateUrl: "blue.html",          controller: "blue_control"        })        .when("/green", {          templateUrl: "green.html",          controller: "green_control"        })      $locationProvider.html5Mode({        enabled: true      });    });    app.controller("blue_control", function($scope) {      $scope.msg = "this is blue";    });    app.controller("green_control", function($scope) {      $scope.msg = "this is green";    });  </script></body></html>
查看完整描述

3 回答

?
猛跑小豬

TA貢獻1858條經(jīng)驗 獲得超8個贊

HTML5模式需要URL重寫。

從文檔中:


HTML5模式

服務(wù)器端

使用此模式需要在服務(wù)器端重寫URL,基本上,您必須重寫所有指向應(yīng)用程序入口點的鏈接(例如index.html)。<base>在這種情況下,要求標(biāo)簽也很重要,因為它使AngularJS能夠區(qū)分作為應(yīng)用程序基礎(chǔ)的url部分和應(yīng)由應(yīng)用程序處理的路徑。


— AngularJS開發(fā)人員指南-使用$ location(HTML5模式服務(wù)器端)


對于NodeJS和ExpressJS

var express = require('express');

var path = require('path');

var router = express.Router();


// serve angular front end files from root path

router.use('/', express.static('app', { redirect: false }));


// rewrite virtual urls to angular app to enable refreshing of internal pages

router.get('*', function (req, res, next) {

    res.sendFile(path.resolve('app/index.html'));

});


module.exports = router;

對于Windows上的IIS

<rewrite>

  <rules>

    <rule name="AngularJS" stopProcessing="true">

      <match url=".*" />

      <conditions logicalGrouping="MatchAll">

        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />

        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />

      </conditions>

      <action type="Rewrite" url="/" />

    </rule>

  </rules>

</rewrite>

請參閱,如何配置IIS以在HTML5模式下用URL重寫AngularJS應(yīng)用程序?


對于阿帕奇

RewriteEngine On RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR] 

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d

RewriteRule ^ - [L]

RewriteRule ^


查看完整回答
反對 回復(fù) 2019-09-27
  • 3 回答
  • 0 關(guān)注
  • 1273 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號