浏览器的地址不会在UI的路线正确显示 [英] Browser address will not be displayed correctly in ui-route

查看:106
本文介绍了浏览器的地址不会在UI的路线正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的例子:

http://angular-ui.github.io/ui-router /采样/#/

在上面的例子中默认页面网址:

  http://angular-ui.github.io/ui-router/sample/#/

但对我来说是这样的:

 的http://本地主机:25768 /管理员#/

为什么?

应该是这样的:

 的http://本地主机:25768 /行政/#/

请注意:系统管理员在MVC控制器

我的codeS:

app.js:

  angular.module('uiRouterApp',[
        uiRouterApp.home',
        ui.router',
        ngAnimate
    ])
    。跑(
        [
            '$ rootScope','$州','$ stateParams',
            功能($ rootScope,$状态,$ stateParams){
                $ rootScope $状态= $状态。
                $ rootScope $ stateParams = $ stateParams。
            }
        ]
    )
    的.config(
        [
            '$ stateProvider','$ urlRouterProvider',
            功能($ stateProvider,$ urlRouterProvider){
                $ urlRouterProvider
                    。当('/ C ID?','/联系人/:身份证')
                    。当('/用户/:身份证','/联系人/:身份证')
                    。除此以外('/');
            }
        ]
    );

home.js:

  angular.module('uiRouterApp.home',[
        ui.router
    ])
    的.config(
        [
            '$ stateProvider','$ urlRouterProvider',
            功能($ stateProvider,$ urlRouterProvider){
                $ stateProvider
                    .STATE('家',{
                        网址:'/',
                        templateUrl:'脚本/ UI路由/家庭/ home.html做为',
                    });
            }
        ]
    );

布局:

 <!DOCTYPE HTML>< HTML NG-应用=uiRouterApp>
< HEAD>
    <间的charset =UTF-8/>
    < META NAME =视口CONTENT =WIDTH =设备宽度,初始规模= 1.0>
    @ Styles.Render(〜/内容/ CSS)
    @ Scripts.Render(〜/包/ Modernizr的)    <标题NG绑定=$ state.current.name +' - UI路由器'> @ ViewBag.Title< /标题>< /头>
<车身类=集装箱adminBackground>
    < D​​IV CLASS =min1170px>
        < D​​IV CLASS =adminHeader>
            < IMG类=adminLeftLogoHeaderSRC =/图像/ juventusLogo.png/>
            < IMG类=adminRightLogoHeaderSRC =/图像/ apkAndroid.png/>
            < D​​IV CLASS =adminTitleHeader>            < / DIV>
        < / DIV>
        <导航类=导航栏导航栏逆角色=导航>
            < D​​IV CLASS =导航栏头>
                <一类=Navbar的品牌UI-SREF =家>主营< / A>
            < / DIV>
            < D​​IV ID =navbarMenuHeader>
                < UL类=NAV导航栏,导航>
                    <立GT;< A HREF =#>退出并LT; / A>< /李>
                < / UL>
                < UL类=NAV导航栏,导航栏导航左>
                    <立GT;< A HREF =#> @ User.Identity.Name< / A>< /李>
                < / UL>
            < / DIV>
        < / NAV>
        < D​​IV ID =身体>
            @RenderSection(精选,必需:false)
            <节>
                @RenderBody()
            < /节>
        < / DIV>
    < / DIV>
    @ Scripts.Render(〜/包/ jQuery的)
    @ Scripts.Render(〜/包/引导)
    @ Scripts.Render(〜/包/ angularJs)
    @RenderSection(脚本,必需:false)
< /身体GT;
< / HTML>

在管理控制器索引页:

  @ {
    ViewBag.Title =经理人;
    布局=../Shared/_AdminLayout.cshtml;
}

更新:

在网址为:的http://本地主机:25768 /系统管理员

和URL更改为:

 的http://本地主机:25768 /管理员#/

没有错误和它的作品。但网址是的http://本地主机:25768 /管理员#/ !!!!不好

在网址为:本地主机:25768 /管理/

所以URL更改为:

 的http://本地主机:25768 /行政/#/

错误角:

  GET HTTP://本地主机:25768 /管理/脚本/ UI路由/家庭/ home.html的404(未找到)


解决方案

首先,我改变templateUrl为

  templateUrl:/Scripts/ui-route/home/home.html',

然后,我改变了code如下:

 公众的ActionResult指数()
        {
            VAR路径= Request的;            如果(路径==/管理员)
            {
                返回重定向(/管理/);
            }            返回查看();
        }

它的工作原理。

I am using the following example :

http://angular-ui.github.io/ui-router/sample/#/

Default Page URL in the example above :

 http://angular-ui.github.io/ui-router/sample/#/

But for me it is like this:

 http://localhost:25768/Admin#/

why ?

Should be like this:

 http://localhost:25768/Admin/#/

note : Admin is Controller in MVC.

my codes :

app.js :

angular.module('uiRouterApp', [
        'uiRouterApp.home',
        'ui.router',
        'ngAnimate'
    ])
    .run(
        [
            '$rootScope', '$state', '$stateParams',
            function($rootScope, $state, $stateParams) {
                $rootScope.$state = $state;
                $rootScope.$stateParams = $stateParams;
            }
        ]
    )
    .config(
        [
            '$stateProvider', '$urlRouterProvider',
            function($stateProvider, $urlRouterProvider) {
                $urlRouterProvider
                    .when('/c?id', '/contacts/:id')
                    .when('/user/:id', '/contacts/:id')
                    .otherwise('/');
            }
        ]
    );

home.js :

angular.module('uiRouterApp.home', [
        'ui.router'
    ])
    .config(
        [
            '$stateProvider', '$urlRouterProvider',
            function($stateProvider, $urlRouterProvider) {
                $stateProvider
                    .state('home', {
                        url: '/',
                        templateUrl: 'Scripts/ui-route/home/home.html',
                    });
            }
        ]
    );

layout :

<!DOCTYPE html>

<html ng-app="uiRouterApp">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")

    <title ng-bind="$state.current.name + ' - ui-router'">@ViewBag.Title</title>

</head>
<body class="container adminBackground">
    <div class="min1170px">
        <div class="adminHeader">
            <img class="adminLeftLogoHeader" src="/Images/juventusLogo.png" />
            <img class="adminRightLogoHeader" src="/Images/apkAndroid.png" />
            <div class="adminTitleHeader">

            </div>
        </div>
        <nav class="navbar navbar-inverse" role="navigation">
            <div class="navbar-header">
                <a class="navbar-brand" ui-sref="home">Main</a>
            </div>
            <div id="navbarMenuHeader">
                <ul class="nav navbar-nav">
                    <li><a href="#">Exit</a></li>
                </ul>
                <ul class="nav navbar-nav navbar-left">
                    <li><a href="#"> @User.Identity.Name</a></li>
                </ul>
            </div>
        </nav>
        <div id="body">
            @RenderSection("featured", required: false)
            <section>
                @RenderBody()
            </section>
        </div>
    </div>
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @Scripts.Render("~/bundles/angularJs")
    @RenderSection("scripts", required: false)
</body>
</html>

Index page in Admin Controller :

@{
    ViewBag.Title = "Manager";
    Layout = "../Shared/_AdminLayout.cshtml";
}

Update :

when url is : http://localhost:25768/Admin

and url change to :

http://localhost:25768/Admin#/

no error and it works. but url is http://localhost:25768/Admin#/ !!!! not good

when url is : localhost:25768/Admin/

so url change to :

http://localhost:25768/Admin/#/

error in angular :

GET http://localhost:25768/Admin/Scripts/ui-route/home/home.html 404 (Not Found) 

解决方案

First, I'm change the templateUrl to

 templateUrl: '/Scripts/ui-route/home/home.html',

Then, I changed the code as follows:

      public ActionResult Index()
        {
            var path = Request.Path;

            if (path == "/Admin")
            {
                return Redirect("/Admin/");
            }

            return View();
        }

It works.

这篇关于浏览器的地址不会在UI的路线正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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