Angular.js中的路由问题 [英] Routing issue in Angularjs
问题描述
我无法根据需要更改URL并调用html
I am not able to change the URL and call html as desired
当我在主页上时,我的URL应该已登录.
When i am at home page my url should have login .
run.plnkr.co/VqxyVuraDTBrBUbZ/
,但我希望将该网址作为 ** run.plnkr.co/loginPage **
run.plnkr.co/VqxyVuraDTBrBUbZ/
but i want the url as **run.plnkr.co/loginPage**
如果您将看到我的controller.js.如果我能够成功登录,则应显示 dashboard.html
,而网址应为 ** run.plnkr.co/Dashboard **
我该如何实现?
And if you will see my controller.js .If i able to succesfully login i should display dashboard.html
and url should **run.plnkr.co/Dashboard**
How can i achieve this ?
我的路由配置如下
(function(){
var app = angular.module('mainApp', ["ngRoute"]);
app.config(function($routeProvider) {
$routeProvider
.when("/main", {
templateUrl: "index.html"
})
.otherwise ( {redirectTo: "/"})
})
}
());
推荐答案
这是路由器文件中所做的更改
Here are the changes made in router file
(function () {
angular.module('mainApp')
.config(function ($routeProvider) {
$routeProvider
.when('/login', {
templateUrl: './login.html',
controller: "LoginCtrl"
})
.when("/dashboard", {
templateUrl: "dashboard.html"
})
.otherwise({ redirectTo: "/login" })
})
}
());
此外,请注意,我还更改了其他几项内容,例如:
Also, note that I have changed several other things like:
- 将
-
controller.js
的名称更改为app.js
- 正确执行
IIFE
controller.js
name toapp.js
- Proper implementation of
IIFE
这篇关于Angular.js中的路由问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!