Removing # from url of angularJS for SEO with backend as Django

前端 未结 2 1317
抹茶落季
抹茶落季 2020-12-11 09:57

I know removing hash from AngularJS is pretty straightforward but the problem is that the backend is in Django.

So, the app works unless the page is refreshed using

相关标签:
2条回答
  • 2020-12-11 10:29

    Use Locationprovider instead of routeProvider and enable html5 to true. https://docs.angularjs.org/api/ng/provider/$locationProvider

    0 讨论(0)
  • 2020-12-11 10:37

    Everything is right. When you refresh the page, firstly request gets processed on the server (and goes to django router). So server should know that it should return your angular page for this URL.

    Let's assume that your page that contains Angular application lives on view called index. Then just point this url to it:

    urlpatterns = [
        url(r'^account/$', index), 
    ]
    

    or point all urls to your view (in case you don't need any other url's to be processed without angular):

    //something like this, not really sure about the regex
    urlpatterns = [
        url(r'^.*$', index), 
    ]
    

    or something like

    urlpatterns = [
        url(r'^/account/.*$', index), 
    ]
    

    You're not alone with this issue: see this and this. So as you can see, it's not Django-specific trouble, but some general client-server workflow.

    0 讨论(0)
提交回复
热议问题