2014-12-04 61 views
1

的URL我配置我的$ routeProvider這樣的:

angular.module('autotestApp').config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider){ 

$locationProvider.html5Mode(true); 

$routeProvider 
    .when('/store', { 
     templateUrl: 'store.html', 
     controller: 'StoreController' 
    }) 
    .when('/groups', { 
     templateUrl: 'groups.html', 
     controller: 'GroupsController' 
    }) 
    .when('/purchases', { 
     templateUrl: 'purchases.html', 
     controller: 'PurchaseController' 
    }) 
    .when('/settings', { 
     templateUrl: 'settings.html', 
     controller: 'SettingsController' 
    }) 
    .otherwise({redirectTo: '/store'}); 

}]); 

,我有以下幾個環節:

<ul> 
    <li><a href="store">Stores</a></li> 
    <li><a href="groups">Groups</a></li> 
    <li><a href="purchases">Purchases</a></li> 
    <li><a href="settings">Settings</a></li> 
</ul> 

當我點擊這些鏈接,它工作正常,但當我手動輸入瀏覽器或當我刷新頁面,我得到「頁面未找到」錯誤

UPDATE:

這是我的urls.py:

urlpatterns = patterns(
    '', 

    url(r'^login', login_user, name='login'), 
    url(r'^logout', logout_user, name='logout'), 
    url(r'^register', register_user, name='register'), 
    url(r'^settings', user_settings, name='settings'), 
    url(r'^reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$', 
     reset_confirm, name='reset_confirm'), 
    url(r'^reset/$', reset, name='reset'), 

    url(r'^purchases', purchases, name='purchases'), 
    url(r'^_store', _store, name='_store'), 

    # payment 
    url(r'^payment/billing/(?P<vouchers_package_id>[0-9]+)$', billing_info, 
     name='billing'), 
    url(r'^payment/success', payment_success, name='payment_success'), 

    # vouchers 
    url(r'^vouchers/send_to_group/(?P<group_id>[0-9]+)', 
     send_vouchers_to_group, name='send_vouchers_to_group'), 
    url(r'^vouchers/send', send_voucher, name='send_voucher'), 

    # students in groups 
    url(r'^groups/students/delete/(?P<group_student_id>[0-9]+)', 
     delete_student, name='delete_student'), 
    url(r'^groups/students/(?P<student_id>[0-9]+)', students, 
     name='student_detail'), 
    url(r'^groups/students', students, name='students'), 

    # groups 
    url(r'^groups/delete/(?P<group_id>[0-9]+)', delete_group, 
     name='delete_group'), 
    url(r'^groups/(?P<group_id>[0-9]+)', groups, name='group_detail'), 
    url(r'^groups', groups, name='groups'), 
    url(r'^$', dashboard_page, name='dashboard'), 
) 

如何解決這一問題?

+2

您必須在您的網絡服務器配置中設置重寫或使用#標記。在哪個網絡服務器上運行? – 2014-12-04 09:07:43

+0

@RaphaelMüller我正在使用Django的服務器 – Rodrigue 2014-12-04 09:09:41

+0

'.html5Mode(true);'需要一些服務器端設置。 – Jai 2014-12-04 09:11:13

回答

0

你必須添加一個包羅萬象的路線在url.py左右

url(r'^', TemplateView.as_view(template_name='index.html')) 

請注意,這個規則必須是最後一個在列表中,因爲它的包羅萬象的路線,一切沒有按不匹配得到這個處理。

+0

我更新我的問題,包括urls.py,你可以看看它嗎?我把所有的路線放在最後。但它沒有幫助:( – Rodrigue 2014-12-04 09:48:12

+0

作爲例子,我們看看'settings'。如果你拿一個仔細看那裏,你會注意到,它已經被定義爲一個路由,因此,你的catch都不會進入,並且在你的路由中定義的視圖發生,而angular只需要服務器上的「一個視圖」,它處理單獨的視圖本身。 – 2014-12-04 10:20:01