【发布时间】:2020-03-28 19:50:38
【问题描述】:
我已成功在 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]
我该如何解决这个问题?.在这方面提供帮助
【问题讨论】:
标签: javascript php angularjs routing routeparams