【问题标题】:Angular Routing and Bootstrap Navbar角度路由和引导导航栏
【发布时间】:2017-03-19 21:22:15
【问题描述】:

我无法让引导导航栏 + 角度路由正常工作。我不明白发生了什么,因为另一个应用程序上的一个非常相似的代码正在运行。

我的 index.html 中有以下 html

<div ng-controller="CoreController as core">
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">myApplication</a>
            </div>
            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                    <li ng-class="core.navHome"><a href="#home">Home <span class="sr-only">(current)</span></a></li>
                    <li ng-class="core.navStatistic"><a href="#statistic">Statistic</a></li>
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container-fluid -->
    </nav>
    <!-- angular templating -->
    <!-- this is where content will be injected -->
    <div ng-view></div>
</div>

我的 app.js:

            $routeProvider.when('/', { templateUrl: 'templates/home.html', controller: 'MainController', controllerAs: 'main' });
            $routeProvider.when('/statistic', { templateUrl: 'templates/statistic.html', controller: 'StatisticController', controllerAs: 'statistic' });
           // Default route
             $routeProvider.otherwise({ redirectTo: '/' });

当我点击统计链接时,我的网址显示: http://localhost/myApplication/#!/#statistic 我看到了主页模板。

然后主页按钮显示“http://localhost/myApplication/#!/

是#!这是什么原因?

【问题讨论】:

  • 尝试删除#。像这样&lt;a class="navbar-brand" href="/"&gt;myApplication&lt;/a&gt;
  • 不改变任何东西。我还删除了缓存以防万一。

标签: angularjs angular-ui-bootstrap navbar angular-route-segment


【解决方案1】:

好的,经过一番研究,我发现我的这段代码适用于 angular

要使上面的代码在 1.6 中工作,你必须去掉 #!通过将其添加到配置中:

$locationProvider.hashPrefix('');

这里是original Post.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-25
    • 2021-08-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多