简体   繁体   中英

AngularJS - UI-Router does not load view

I'm in an app that uses angular-route and I'm trying to integrate ui-router into a particular module. In this module, I have not included angular-route .

The ui-sref urls will all generate fine, but when a user tries to navigate to the view, it kicks back to root.

Can angular-route and ui-router co-mingle?

angular.module('StyleGuide', ['ui.router'])
  .config(['$stateProvider', '$urlRouterProvider',
    function ($stateProvider, $urlRouterProvider) {

        $urlRouterProvider.otherwise('/StyleGuide/');

        // Configure UI-Router
        $stateProvider
            .state('styleguide', {
                url: '/StyleGuide/',
                templateUrl: 'App/StyleGuide/styleguide.html'
            })
            .state('styleguide.sandbox', {
                url: '/StyleGuide/Sandbox',
                templateUrl: 'App/StyleGuide/sandbox/sandbox.html',
                controller: 'SandboxController'
            });
    }
  ]);

HTML

<div class="sgHeader">
    <div class="navbar navbar-default">
        <nav class="container-fluid">
            <ul class="nav navbar-nav">
                <li class="dropdown open" uib-dropdown >
                    <a role="button" class="dropdown-toggle" uib-dropdown-toggle aria-haspopup="true" aria-expanded="true">
                        <i class="fa fa-bars"></i>
                    </a>
                    <ul class="dropdown-menu" uib-dropdown-menu aria-labelledby="simple-dropdown">
                        <li><a ui-sref="styleguide.sandbox"><i class="fa fa-hourglass-start"></i>Sandbox</a></li>

                    </ul>
                </li>
            </ul>
            <div class="navbar-header">
                <a class="navbar-brand" ui-sref="styleguide"><span class="heavy">Soar </span>Styleguide</a>
            </div>
        </nav>
    </div>
</div>
<div class="sg__body" ui-view>
    <div style="text-align: center;">
        <h1>The Soar Style Guide, this is.</h1>
        <h3>Use it to promote codebase and visual consistency, you will.</h3>
        <img src="https://s-media-cache-ak0.pinimg.com/originals/49/7d/80/497d80f923e70aaa558d17c9cd1ee142.gif" />
    </div>
</div>

In the child State - 'styleguide.sandbox' change the URL from '/StyleGuide/Sandbox' to '/Sandbox'. Since you have already mentioned sandbox to be a child of styleguide, the router will automatically treat the URL for sandbox as '/StyleGuide/Sandbox', you don't have to specifically mention it.

问题在于在另一个模块中的流氓otherwise语句。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM