Javascript 如果base href设置为非'/';
我对AngularJS是新手。我目前在为我的视图编写漂亮的URL时遇到了问题从地址栏中显示的URL中删除Javascript 如果base href设置为非'/';,javascript,angularjs,single-page-application,angularjs-routing,Javascript,Angularjs,Single Page Application,Angularjs Routing,我对AngularJS是新手。我目前在为我的视图编写漂亮的URL时遇到了问题从地址栏中显示的URL中删除#。但是,这样做后,我无法重新路由到所需的视图。 我不断收到错误无法获取/登录 当第一次启动应用程序时,我会看到主页/login,但当我刷新页面时,我会看到相同的错误 这里是应用程序的主页(index.html) 我还作了以下重要观察 如果我将index.html上的base href设置为指向根 并根据需要执行重新路由 $routeProvider.when("/", { t
#
。但是,这样做后,我无法重新路由到所需的视图。
我不断收到错误无法获取/登录
当第一次启动应用程序时,我会看到主页/login
,但当我刷新页面时,我会看到相同的错误
这里是应用程序的主页(index.html)
我还作了以下重要观察
$routeProvider.when("/", {
templateUrl : "views/login.html",
controller : "loginController"
}).when("/drivers", {
templateUrl : "views/drivers.html",
controller : "driversController"
}).when("/drivers/:id", {
templateUrl : "views/driver.html",
controller : "driverController"
}).otherwise({
redirectTo : "/"
});
我的应用程序在这里运行良好。但我希望“/login”成为我的默认页面。请告诉我哪里出了问题,或者这是AngularJS本身的问题。除了启用
HTML5模式
之外,您还需要更新服务器端以将所有请求重定向到单个入口点,如/login
或/home
等
服务器端
使用这种模式需要在服务器端重写URL,基本上您必须重写所有指向应用程序入口点的链接(例如index.html)
在此文档页面上搜索“服务器端”:
你能发布小提琴或钢琴的链接吗?你能告诉我你是如何解决的吗。我面临着类似的问题,我目前正在使用Angular的$httpBackend功能模拟我的应用程序。我在grunt服务器上运行它。在阅读了你的回复和以下内容后,我解决了这个问题。谢谢……)
angular.module('F1FeederApp.controllers', []);
angular.module('F1FeederApp',
[ 'F1FeederApp.services', 'F1FeederApp.controllers', 'ngRoute' ])
.config([ '$routeProvider','$locationProvider', function($routeProvider,$locationProvider,$location) {
console.log('---------------inside config----------------');
console.log($routeProvider);
$routeProvider.when("/login", {
templateUrl : "views/login.html",
controller : "loginController"
}).when("/drivers", {
templateUrl : "views/drivers.html",
controller : "driversController"
}).when("/drivers/:id", {
templateUrl : "views/driver.html",
controller : "driverController"
}).otherwise({
redirectTo : "/login"
});
$locationProvider.html5Mode(true);
} ]);
$routeProvider.when("/", {
templateUrl : "views/login.html",
controller : "loginController"
}).when("/drivers", {
templateUrl : "views/drivers.html",
controller : "driversController"
}).when("/drivers/:id", {
templateUrl : "views/driver.html",
controller : "driverController"
}).otherwise({
redirectTo : "/"
});