[英]Angular JS page not loading properly in beginning
这是我对angularJS应用程序的配置。
sampleApp.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise("/Home");
$stateProvider
.state('Product', {
templateUrl: "templates/Products.html",
url: '/Product',
controller: 'MainCtrl2 as pc'
})
.state('Login', {
templateUrl: "templates/Login.html",
url: "/Login",
controller: 'loginCtrl'
})
.state('SignUp', {
templateUrl: "templates/SignUp.html",
url: "/SignUp",
controller: 'SignUpController'
})
.state('Home', {
templateUrl: "templates/Home.html",
url: "/Home"
})
.state('Feedback', {
templateUrl: "templates/Feedback.html",
url: "/Feedback"
})
;
});
问题是当我输入我的域名,例如example.com时,我希望它转换为http://example.com/#/Home ,但是有时(10之6)不能将example.com更改为http: //example.com/#/Home ,因此应用程序无法正确加载。
一旦我单击了已卸载应用程序中的任何链接,它就会开始正常工作。
如何确保每次页面加载正确。
而不是直接添加
$urlRouterProvider.otherwise("/Home");
尝试使用以下路线
$urlRouterProvider
.when('/', function ($state) {
$state.go('Home');
}).otherwise('/Home');
我相信这可以解决您的问题: http : //niclassahlin.com/2014/05/31/kickstarting-angular-ui-router/
app.run(['$state', function ($state) {}])
本质上,您需要在应用运行时启动路由器,以确保初始化其他路由。 不知道为什么您当前的应用偶尔会正确路由而不看到完整的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.