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
  path: '/{req}'
  defaults: { _controller: App\Controller\FrontendController::index }
    req: "^((?!api).)*$"

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