When building single page applications, I still base them on top of symfony as I want to use the Symfony profiler. The whole routing should still take place in the frontend, so I want to redirect all routes to the frontend except those starting with /api.

To archive this I've used a catch all route with a regular expression as requirement for the route:

# Frontend
frontend_index:
  path: '/{req}'
  defaults: { _controller: App\Controller\FrontendController::index }
  requirements:
    req: "^((?!api).)*$"

Add this route as the first and all routes for your API after it.