角度路由;网址

时间:2017-01-22 00:14:22

标签: angularjs routing route-provider location-provider

我尝试做路由,但我不能。

app.js中的相关代码;

var app = angular.module("app",['ngRoute']);

app.config(["$routeProvider",function($routeProvider){


    $routeProvider.
        when('/', {
            templateUrl:'pages/home.php'
        }).
        when('/notifications', {
            templateUrl:'pages/notifications.php'
        }).
        when('/messages', {
            templateUrl:'pages/messages.php'
        }).
        when('/search', {
            templateUrl:'pages/search.php'
        }).
        otherwise({
            rediectTo: '/'
        });

}])

index.php中的相关代码;

<div id="ifmenu">
    <div class="ifmitem" href="/#/">Anasayfa</div>
    <div class="ifmitem" href="/#/notifications">Bildirimler</div>
    <div class="ifmitem" href="/#/messages">Mesajlar</div>
    <div class="ifmitem" href="/#/search">Arama</div>
</div>
<ng-view></ng-view>

在url中的hashtag旁边有感叹号。像这样:(localhost / app /#!)。我可以通过其他()函数获得home.php但链接不起作用。我在互联网上打电话解决了这个问题。我看到我应该&#39;添加这些亚麻布;

$locationProvider.html5Mode({
    enabled: true,
    requireBase: false
});

我在.config中添加了$ locationProvider。但这次没有代码可以工作。

应该&#39;我呢?

1 个答案:

答案 0 :(得分:1)

您无法使用href属性div标记。您应该在div标签中创建标签。