title: Django routing with VueJS single page has unexpected behaviour when there is no trailing slash in the URL
body: <p>I have a Django backend, VueJS frontend combination, where I serve a REST API via Django and a single page application with VueJS and vue-router.</p>
  
  <p>From <a href="https://stackoverflow.com/questions/42864641/handling-single-page-application-url-and-django-url">this</a> question I got the tip to use the following urls in my main urls.py:</p>
  
  <pre><code>urlpatterns = [
      re_path(r'^(?P&lt;filename&gt;(robots.txt)|(humans.txt))$', views.home_files, name='home-files'),
      path('api/', include('backend.urls', namespace='api')),
      path('auth/', include('auth.urls')),
      path('admin/', admin.site.urls),
      re_path(r'^.*$', views.vue), # VueJS frontend
  ]
  </code></pre>
  
  <p>So I want URLs to behave like this:  </p>
  
  <pre><code>{baseDomain}/api/users/1/ -&gt; go to backend.urls  
  {baseDomain}/auth/login/ -&gt; go to auth.urls  
  {baseDomain}/admin/ -&gt; go to admin page  
  {baseDomain}/de/home -&gt; vue-router takes over
  </code></pre>
  
  <p>Now these URLs work perfectly fine, however I would expect that {baseDomain}/api/users/1 (without trailing slash) would still go to backend.urls, however what happens is that I land on the Vue page.</p>
  
  <p>Adding APPEND_SLASH = True in settings.py does not help either, since it only appends a slash if it didn't find a page to load. But since the regex for my frontend matches anything it always redirects to Vue.</p>
  
  <p>My attempt was to fix it by adding:  </p>
  
  <pre><code>re_path(r'.*(?&lt;!/)$', views.redirect_with_slash)
  </code></pre>
  
  <p>with the following code:</p>
  
  <pre><code>def redirect_with_slash(request):
      '''Redirects a requested url with a slash at the end'''
      if request.path == '/':
          return render(request, 'frontend/index.html')
      return redirect(request.path + '/')
  </code></pre>
  
  <p>But it isn't a very elegant one. Also mind the <code>if request.path == '/':</code>. Weirdly enough, Django would match '/' with the regex <code>r'.*(?&lt;!/)$'</code> and then redirect to '//', which is an invalid URL and show an error page, so I had to include this if-statement.</p>
  
  <p>Does anyone have a solution for this? In the referenced question this did not seem to be an issue, so I wonder why it is in my project.</p>
  
  <p>EDIT: backend urls.py</p>
  
  <pre><code>"""
  backend urls.py
  """
  from django.urls import include, path
  from rest_framework_nested import routers
  from auth.views import UserViewSet, GroupViewSet, ProjectViewSet
  from .views import IfcViewSet, IfcFileViewSet
  
  app_name = 'api'
  
  router = routers.DefaultRouter() #pylint: disable=C0103
  router.register(r'users', UserViewSet)
  router.register(r'groups', GroupViewSet)
  router.register(r'projects', ProjectViewSet)
  projects_router = routers.NestedSimpleRouter(router, r'projects', lookup='project')
  projects_router.register(r'models', IfcFileViewSet, base_name='projects-models')
  
  urlpatterns = [
      path('', include(router.urls)),
      path('', include(projects_router.urls))
  ]
  </code></pre>
  
  <hr>
  
  <pre><code>"""
  auth urls.py
  """
  from django.urls import path, include
  from rest_framework import routers
  from rest_framework_jwt.views import obtain_jwt_token, refresh_jwt_token
  from .views import RegistrationViewSet
  
  app_name = 'authentication'
  router = routers.DefaultRouter()
  router.register('register', RegistrationViewSet)
  
  urlpatterns = [
      path('', include(router.urls)),
      path('', include('rest_auth.urls')),
      path('refresh_token/', refresh_jwt_token),
  ]
  </code></pre>