Angular.js中的路由问题 [英] Routing issue in Angularjs

查看:63
本文介绍了Angular.js中的路由问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法根据需要更改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 to app.js
  • Proper implementation of IIFE

这篇关于Angular.js中的路由问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆