Ad

Removing # From Url Of AngularJS For SEO With Backend As Django

- 1 answer

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 "F5".

so, http://127.0.0.1:8000/account works if the button is clicked but refreshing the page gives me Page not found as the server searches for it in urls.py file

Can someone please suggest me any fix for this ?

Ad

Answer

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.

Ad
source: stackoverflow.com
Ad