AngularJS routing vs backend routing

前端 未结 2 1232
南旧
南旧 2021-02-02 17:56

I would like to use AngularJS in my next project. The application with Python backend and html5, Angular frontend.

I am going to use MVC framework on backend and I am li

2条回答
  •  一个人的身影
    2021-02-02 18:16

    You can use client-side routing and let the backend return static files and JSON data. The routing in Angular basically tell you which partial template you need to download from server and which controller will handler it.

    Your back end routes will be like this

    '/partials/:name' -> return corresponding partial
    
    '/api/*' -> handlers to return json data
    
    '/*' -> return index.html
    

    Your index.html will contain reference to other views

    ...
    
    ...

    Now let say you go to yourapp.com/someview.html. The server returns index.html and since the url is /someview, Angular will ask for "someview" partial from server and render the page accordingly.

    In short, the server role is to return index.html, partials and serve REST API request. The client always receive index.html and based on the url, request for coressponding partials and JSON data.

提交回复
热议问题