简体   繁体   English

AngularJS SPA刷新页面

[英]AngularJS SPA Refresh page

While developing some SPA AngularJS Application I define the rooting with $routeProvider. 在开发一些SPA AngularJS应用程序时,我用$ routeProvider定义了根目录。 Everythings works fine, but I get tired with clicking through the whole application to see particular changes I've done anytime I republish the application to the server. 一切正常,但是我厌倦了单击整个应用程序以查看将应用程序重新发布到服务器时所做的特定更改。 Is there a possibility to change this behaviour? 有可能改变这种行为吗? I mean, when I hit refresh on my browser or use some tools for automatical refreshing (like LiveReload Server) is there a way to tell angularJS to not to navigate to the default page? 我的意思是,当我在浏览器中单击“刷新”或使用某些工具进行自动刷新(例如LiveReload Server)时,是否有办法告诉angularJS不要导航至默认页面?

Regarding to the comments below, here is the routing content. 关于以下注释,这是路由内容。

Below is the MainRoutingContent 以下是MainRoutingContent

 'use strict' angular.module('MainModule') .config(['$routeProvider', function ($routeProvider) { $routeProvider .when('/login', { controller: 'LoginController', templateUrl: 'webapp/modules/authentication/views/login.html', hideMenus: true }) .when('/register', { controller: 'RegistrationController', templateUrl: 'webapp/modules/registration/views/register.html' }) .when('/', { controller: 'HomeController', templateUrl: 'webapp/modules/home/views/home.html' }) .otherwise({ redirectTo: '/login' }); }]); 

The single html page has the ng-view defined: 单个html页面定义了ng-view:

 <div> <div ng-view></div> </div> 

And some additional for the RegistrationModule: 还有一些其他的RegistrationModule:

 angular.module('RegistrationModule') .config(['$routeProvider', function ($routeProvider) { $routeProvider .when('/register/user', { controller: 'UserRegistrationController', templateUrl: 'webapp/modules/registration/views/register-user.html' }) .when('/register/company', { controller: 'CompanyRegistrationController', templateUrl: 'webapp/modules/registration/views/register-company.html' }); }]); 

Ok, I got it. 好,我知道了。 I defined some run block in the main module of my application with the redirection to the /login page. 我通过重定向到/ login页面在应用程序的主模块中定义了一些运行块。 Here is the code: 这是代码:

 angular.module("app", [...]) .run(['$location', function ($location) { $location.path('/login'); }]) 

If someone will get such an issue with refreshing the page in the future, please look for some run block defined in your code. 如果将来有人在刷新页面时遇到此类问题,请查找代码中定义的一些运行块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM