Tag: 路由提供者

URL在浏览器刷新时发生变化($ routeProvider用于客户端路由)

我使用Angular作为客户端和Nodejs(Express)作为服务器端来构build单页应用程序。 为了支持不同视图的浏览器历史,我正在使用$ routeProvider。 如果我不刷新浏览器,效果很好。 但是,每当我刷新浏览器,我注意到URL被更改,造成问题,因为该URL模式不存在于服务器。 以下是更多细节。 Angular js路由器代码: $routeProvider. when('/categoryview', { templateUrl: 'templates/partials/app/categoryview/CategoryView.html', controller: 'ApplicationController' }). when('/:categoryId/themes', { templateUrl: 'templates/partials/app/themeview/ThemeView.html', controller: 'ThemeViewController' }) .otherwise({redirectTo: '/categoryview'}); 作为第一次启动的应用程序的浏览器中的URL: http://localhost:3000/themelibrary#/categoryview 刷新浏览器中的URL: http://localhost:3000/categoryview#/categoryview 如果你注意到,那么你会发现根URL “/ themelibrary”被改成“/ categoryview” ,由于服务器不支持“/ categoryview”而导致问题。 我也尝试了不同版本的Angularjs,但没有成功。 请帮助,让我知道是否需要更多的代码来解释这个问题。 编辑:添加Nodejs路由器的详细信息UI路由: module.exports = function(app, passport) { // route for home page app.get('/', function(req, res) { res.redirect('/login'); }); //Route […]

重新加载angular度的应用程序后没有index.html

我有一个像下面这样的基本设置的angular.js应用程序:我的index.html呈现像Top / Sidebar这样的静态内容。 里面我有<div ng-view></div>来显示部分html文件,例如我的home.html login到我的应用程序后, index.html与它的Controller MainCtrl加载,以及我的home.html与相应的HomeCtrl 。 所以一切都应该如此。 我实施了一个修复程序(以便重新加载不会“忘记”用户,我不会注销 – 我基于http://www.sitepoint.com/implementing-authentication-angular-applications/示例)我试过重新加载我的网页。 但现在只有我的home.html加载。 注意:我在下面编辑了我的发现 这是有道理的,这是我的app.js的一部分: $routeProvider.when('/', { templateUrl: 'views/home.html', controller: 'HomeCtrl', resolve: { auth: function ($q, authenticationSvc) { var userInfo = authenticationSvc.getUserInfo(); if (userInfo) { return $q.when(userInfo); } else { return $q.reject({ authenticated: false }); } } } }) .when('/login', { templateUrl: 'views/login.html', controller: […]