Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度UI路由器和嵌套状态_Javascript_Angularjs_Routing_Angular Ui Router_Angularjs Routing - Fatal编程技术网

Javascript 角度UI路由器和嵌套状态

Javascript 角度UI路由器和嵌套状态,javascript,angularjs,routing,angular-ui-router,angularjs-routing,Javascript,Angularjs,Routing,Angular Ui Router,Angularjs Routing,我试图让我的嵌套状态工作,但我不知道我做错了什么 正文: 你能告诉我,我做错了什么吗?因为你的摘要状态在URL中有/,这意味着当你创建子状态时,它可以有/child的URL将被视为//child 根据当前代码,它应该是$urlRouterProvider。否则('//child') 但从技术上讲,为了使URL对用户友好,您应该使用空白(')URL声明抽象状态 .state('main'{ 摘要:没错, url:“”,//可能是因为您想使用HTML5路由,在这种情况下,您需要添加$locati

我试图让我的嵌套状态工作,但我不知道我做错了什么

正文:


你能告诉我,我做错了什么吗?

因为你的
摘要
状态在URL中有
/
,这意味着当你创建子状态时,它可以有
/child
的URL将被视为
//child

根据当前代码,它应该是
$urlRouterProvider。否则('//child')

但从技术上讲,为了使URL对用户友好,您应该使用空白(
'
)URL声明抽象状态

.state('main'{
摘要:没错,

url:“”,//可能是因为您想使用HTML5路由,在这种情况下,您需要添加
$locationProvider.html5Mode(true);
谢谢,但这会使我的所有相关路径崩溃:-(谢谢,我删除了“child”之前的“/”.现在它起作用了。@Martin是的,我确实更新了我的答案..不过用了那个解决方案..这是做这件事的最佳解决方案。。
<div class="site_container" ui-view></div> 
<header class="main_header">
    <h1>My header</h1>
</header>

<main  ui-view></main>
<h2>My content</h2>
<div class="site_container" ui-view>
    <header class="main_header">
        <h1>My header</h1>
    </header>

    <main  ui-view>
        <h2>My content</h2>
    </main>
</div> 
angular.module('myApp').config([
'$stateProvider',
'$urlRouterProvider',
function (
    $stateProvider,
    $urlRouterProvider
    ) {

    $stateProvider

    .state('main', {
        abstract: true,
        url: '/',
        templateUrl: 'app.html'
    })
    .state('main.child', {
        url: '/child',
        templateUrl: 'child.html',
    })

    // if none of the above states are matched, use this as the fallback
    $urlRouterProvider.otherwise('/child');
}]);
.state('main', {
    abstract: true,
    url: '', //<--changed to blank URL
    templateUrl: 'app.html'
})