ui-route中浏览器地址无法正确显示 | route中浏览器地址无法正确显示 本文介绍了ui-route中浏览器地址无法正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下示例:
http://angular-ui.github.io/ui-路由器/样本/#/
上例中的默认页面 URL:
http://angular-ui.github.io/ui-router/sample/#/
但对我来说是这样的:
http://localhost:25768/Admin#/
为什么?
应该是这样的:
http://localhost:25768/Admin/#/
注意:Admin 是 MVC 中的控制器.
我的代码:
app.js :
angular.module('uiRouterApp', ['uiRouterApp.home','ui.router','ngAnimate']).跑(['$rootScope', '$state', '$stateParams',函数($rootScope,$state,$stateParams){$rootScope.$state = $state;$rootScope.$stateParams = $stateParams;}]).config(['$stateProvider', '$urlRouterProvider',功能($stateProvider,$urlRouterProvider){$urlRouterProvider.when('/c?id', '/contacts/:id').when('/user/:id', '/contacts/:id').除此以外('/');}]);
home.js :
angular.module('uiRouterApp.home', ['ui.router']).config(['$stateProvider', '$urlRouterProvider',功能($stateProvider,$urlRouterProvider){$stateProvider.state('家', {网址:'/',templateUrl: 'Scripts/ui-route/home/home.html',});}]);
布局:
<html ng-app="uiRouterApp"><头><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>头部><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">
<nav class="navbar navbar-inverse" role="navigation"><div class="navbar-header"><a class="navbar-brand" ui-sref="home">Main</a>
<div id="navbarMenuHeader"><ul class="nav navbar-nav"><li><a href="#">退出</a></li><ul class="nav navbar-nav navbar-left"><li><a href="#">@User.Identity.Name</a></li>
</nav><div id="body">@RenderSection("特色",必填:false)@RenderBody()</节>
@Scripts.Render("~/bundles/jquery")@Scripts.Render("~/bundles/bootstrap")@Scripts.Render("~/bundles/angularJs")@RenderSection("scripts", required: false)
</html>
管理控制器中的索引页面:
@{ViewBag.Title = "经理";布局 = "../Shared/_AdminLayout.cshtml";}
更新:
当 url 为:http://localhost:25768/Admin
和网址更改为:
http://localhost:25768/Admin#/
没有错误,它可以工作.但 url 是 http://localhost:25768/Admin#/
!!!不好
当 url 为:localhost:25768/Admin/
所以网址更改为:
http://localhost:25768/Admin/#/
角度错误:
GET http://localhost:25768/Admin/Scripts/ui-route/home/home.html 404(未找到)
解决方案
首先,我将 templateUrl 更改为
templateUrl: '/Scripts/ui-route/home/home.html',
然后,我将代码更改如下:
public ActionResult Index(){var path = Request.Path;如果(路径==/管理员"){返回重定向(/管理员/");}返回视图();}
它有效.
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-route中浏览器地址无法正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-02 03:36