Real URLs with single page apps?

I used a reactive router for one of my projects, so respond to the frontend library, and the managed routes are managed by the router, and the backend is in django and apis in django rest

So, I was looking at the documentation with the jet router, and I came across this: -

Server setup Your server should be ready to handle real URLs. When the application first loads with /, it will probably work, but as the user moves and then updates in / accounts / 23, your web server will receive the request / accounts / 23. You will need to process this URL address and include your javascript app in response. **

I was wondering how this would work with django views.

+4
source share
1 answer

On the development server, you just set up a route for everything that doesn't start with api/or static/to return the main file app.html. Example

class AppHTMLView(View):

    def get(self, request):
        fn = os.path.join(settings.BASE_DIR, "app", "app.html")
        with open(fn, 'r') as fh:
            return HttpResponse(fh.read())

And on your production server, you configure Nginx accordingly. Something like that

...
location / {
    root /var/www/example.com/static_files/;
    try_files '' /app.html =404;
}

But this is in no way characteristic of React, but is common to all single-page applications.

+3
source

All Articles