gpt4 book ai didi

javascript - Angular 斜线被编码

转载 作者:可可西里 更新时间:2023-11-01 14:50:47 33 4
gpt4 key购买 nike

我和这个人有同样的问题:

angularjs-slash-after-hashbang-gets-encoded

URL 被编码并且没有正确路由,在我的路由配置中它似乎是错误的。还没有找到原因,我的 URL 重写工作正常。唯一的异常(exception)是当我在 HTML5 模式下在 URL 中添加 hashbang 时。我希望回退到 hashbang 并将 URL 重写为 html5 模式。

有人知道这里发生了什么吗?

更新:我将详细说明之前提供的信息:

我在服务器端使用 apache,在 .htaccess 中使用以下配置:

Options +FollowSymLinks
IndexIgnore */*
DirectoryIndex index.html index.htm
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept"
</IfModule>



# html5 pushstate (history) support:

<ifModule mod_rewrite.c>
RewriteEngine on

# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
</ifModule>

我的 $locationProvider 和路由配置:

App.config(function($routeProvider, $sceDelegateProvider, $locationProvider) {

$locationProvider.html5Mode(true);
$locationProvider.hashPrefix('!');


$routeProvider.when('/route1/:param', {
templateUrl: '/html/route1.html',
controller: 'Route1Ctrl'

});

$routeProvider.when('/', {
templateUrl: '/html/route1.html',
controller: 'Route1Ctrl'
});

$routeProvider.when('/route2', {
templateUrl: '/html/route2.html',
controller: 'Route2Ctrl'
});

$routeProvider.when('/route3', {
templateUrl: '/html/route3.html',
controller: 'Route3Ctrl'
});

$routeProvider.when('/route4', {
templateUrl: '/html/route4.html',
controller: 'Route4Ctrl'
});

$routeProvider.when('/route5', {
templateUrl: '/html/route5.html',
controller: 'Route5Ctrl'
});

$routeProvider.when('/route6', {
redirectTo: '/route4'
});


$routeProvider.otherwise({
redirectTo: "/"
});


});

最佳答案

我终于通过两件事解决了这个问题:

1.- 我添加了 <base href="/">到 index.html
2.- 我激活了 HTML5 模式但没有前缀

这样我就可以使用 http://localhost/#/routehttp://localhost/route并且 URL 被正确重写。

关于javascript - Angular 斜线被编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19741919/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com