angularjs中的URL路由不起作用 [英] Url routing in angularjs is not working

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

问题描述



这里我有3个登录cshtml文件,当我们在abc.com/1这样的地址栏中写入时,需要

加载login1.cshtml以及何时我们打电话给abc.com/2需要打电话给login2.cshtml,如果它是

abc.com/3应该打电话给login3.cshtml。



任何帮助将不胜感激。



问候,

Soumya。



我尝试过:



  var  myApp = angular.module('  myApp',[]); 

myApp .config( function ($ routeProvider,$ locationProvider){

$ routeProvider

// 主页的路线
.when(' / 1',{
templateUrl:' Login / Login.cshtml'
,controller:' 登录/登录

})

// 约会页面的路线
.when(' / 2',{
templateUrl:' Login / Login1.cshtml'
, controller:' 登录/登录1'
})

// 联系页面的路线
.when(' / 3',{
templateUrl:' Login / Login2.cshtml'
,controller :' Login / Login2'
});

// 使用HTML5历史记录API
$ locationProvider。 html5Mode( true );
});

解决方案

routeProvider,


locationProvider){

routeProvider

// 主页路由
.when(' / 1',{
templateUrl:< span class =code-string>' Login / Login.cshtml'
,controller:' 登录/登录'

})

// 关于页面的路线
.when(' < span class =code-string> / 2',{
templateUrl:' 登录/Login1.cshtml'
,控制器:' 登录/登录1'
})

// 联系页面的路线
.when(' / 3',{
templateUrl:' Login / Login2.cshtml'
,controller:' Login / Login2'
});

// 使用HTML5历史记录API


Hi,
Here I have 3 login cshtml files,when we write in address bar like abc.com/1 ,needs to
load login1.cshtml and when we call abc.com/2 needs to call login2.cshtml and if it is
abc.com/3 login3.cshtml should be call.

Any help would be greatly appreciated.

Regards,
Soumya.

What I have tried:

var myApp = angular.module('myApp ',[]);

myApp .config(function ($routeProvider, $locationProvider) {

        $routeProvider

        // route for the home page
        .when('/1', {
            templateUrl: 'Login/Login.cshtml'
           , controller: 'Login/Login'

        })

        // route for the about page
        .when('/2', {
            templateUrl: 'Login/Login1.cshtml'
           , controller: 'Login/Login1'
        })

        // route for the contact page
        .when('/3', {
             templateUrl: 'Login/Login2.cshtml'
           , controller: 'Login/Login2'
        });

        // use the HTML5 History API
        $locationProvider.html5Mode(true);
    });

解决方案

routeProvider,


locationProvider) {


routeProvider // route for the home page .when('/1', { templateUrl: 'Login/Login.cshtml' , controller: 'Login/Login' }) // route for the about page .when('/2', { templateUrl: 'Login/Login1.cshtml' , controller: 'Login/Login1' }) // route for the contact page .when('/3', { templateUrl: 'Login/Login2.cshtml' , controller: 'Login/Login2' }); // use the HTML5 History API


这篇关于angularjs中的URL路由不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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