我已经成功地在 Angular js 和 PHP 文件中添加了路由参数。但我需要为一个文件添加 URL 参数。我补充说。但它显示一个错误。
我附上了下面的代码
var mainbread = angular.module('mainbread', ['ngSanitize', 'ui-notification','ngRoute', 'ngStorage',
'angular.filter', 'moment-picker', 'ngMaterial', '720kb.socialshare'])
mainbread.config(function (NotificationProvider, $routeProvider, $locationProvider) {
NotificationProvider.setOptions({
delay: 5000,
startTop: 40,
startRight: 40,
verticalSpacing: 20,
horizontalSpacing: 20,
positionX: 'right',
positionY: 'top'
}),
$routeProvider
.when("/", {
templateUrl : "/home.php",
controller: "maincontrol"
})
.when("/donate", {
templateUrl : "/donate.php",
controller: "maincontrol"
})
.when("/donate/:raiser", {
templateUrl : "/donate.php",
controller: "donatectrl"
})
.when("/about", {
templateUrl : "/about.php",
controller: "maincontrol"
})
.when("/blog", {
templateUrl : "/blog.php",
controller: "maincontrol"
})
.when("/contact", {
templateUrl : "/contact.php",
controller: "maincontrol"
})
.when("/terms", {
templateUrl : "/terms.php",
controller: "maincontrol"
})
.when("/policy", {
templateUrl : "/policy.php",
controller: "maincontrol"
});
$locationProvider.html5Mode(true);
});
// 'use strict';
mainbread.controller('maincontrol', ['$scope', '$filter', '$http', 'Notification', '$compile', '$window', '$rootScope', '$location', '$mdDialog',
function ($scope, $filter, $http, Notification, $compile, $window, $rootScope, $location, $mdDialog) {
}]);
mainbread.controller('donatectrl', ['$scope', '$filter', '$http', 'Notification', '$compile', '$window', '$rootScope', '$location', '$mdDialog','$routeParams',
function ($scope, $filter, $http, Notification, $compile, $window, $rootScope, $location, $mdDialog,$routeParams) {
$scope.raiser = $routeParams.raiser;
alert("$scope.raiser");
}]);
在上面的代码中,我添加了路由参数“ raiser ”。当我在 URL 中使用一些参数时,例如domain/donate/myid,URL 将donate视为一个目录。所以错误显示如下
我也为此写了.htaccess。附上下面的代码。这有什么问题吗?
RewriteEngine On
Options FollowSymLinks
RewriteBase /
DirectoryIndex main.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /#/$1 [L]
我该如何解决这个问题?.give help in this