Manage urls just by AngularJS

2019-07-19 02:47发布

In my AngularJS app i've made a simple URL configuration by Angular-UI-router:

config(function($stateProvider, $urlRouterProvider, $locationProvider){
            $urlRouterProvider.otherwise("/");

            $stateProvider
                .state({
                    name: 'land',
                    url: "/",
                    templateUrl: "main_ang.html",
                    controller: 'showSomethingCtrl'
                })
                .state({
                    name: 'tournaments',
                    url: "tournaments/",
                    templateUrl: 'tournaments_list_ang.html',
                    controller: 'showTournamentsCtrl'
                });
            $locationProvider.html5Mode(true);
        })

First this app was Django based, but right now i want it to be rewritten in terms of Django Rest Framework and AngularJS, that is why i commented out '/tournaments/' URL from Django's urls.py:

urlpatterns = patterns('',
                       url(r'^$', "chess_tournaments.views.Main", name='main'),
                       # url(r'^tournaments/$', 'chess_tournaments.views.TournamentsView', name='tournaments'),
                       # url(r'^tournament/(?P<tournament_id>\d+)/$', 'chess_tournaments.views.TournamentDetailView',
                       #     name='tournament_detail'),
                       url(r'^tournament_new/$', 'chess_tournaments.views.TournamentDetailView', name='tournament_new'),...

Everything goes well when i navigate to 127.0.0.8000 first and then click proper link with ui-sref="tournaments". But navigating to 127.0.0.8000/tournaments leads to "Page not found (404)" error. I guess i should serve angular's app first to client's browser, but what is the right way to do that?

0条回答
登录 后发表回答