# 404 Routing and JavaScript Frameworks

**URL:** <https://discourse.slimframework.com/t/404-routing-and-javascript-frameworks/585>\
**Category:** Questions\
**Created:** [August 5, 2016, 9:17pm UTC](https://discourse.slimframework.com/t/404-routing-and-javascript-frameworks/585 "2016-08-05T21:17:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ebakunin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/ebakunin/32/187_2.png) [@ebakunin](https://discourse.slimframework.com/u/ebakunin)\
**Post date:** [August 5, 2016, 9:17pm UTC](https://discourse.slimframework.com/t/404-routing-and-javascript-frameworks/585/1 "2016-08-05T21:17:48Z")

</div>

I am building a site that uses Angular 2 for its front end framework. Angular has its own 404 handler. For it to work all server side 404s need to load the index template.

(simplified, in pseudo-code)

- My app only has one route, which renders with predefined `$args`  
.

- The user goes to `http://example.com/missing`, which does not exist.

- The app needs to load `index.phtml`, **along with the related `$args`** , without redirecting the user (i.e. the URL will still read `http://example.com/missing`)

I assume I need to override the _notFoundHandler_ function, but I do not know how to correctly add the behavior. How can I do this in Slim? Thanks.

---

<div class="post-metadata">

**Author:** ![ebakunin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/ebakunin/32/187_2.png) [@ebakunin](https://discourse.slimframework.com/u/ebakunin)\
**Post date:** [August 5, 2016, 10:36pm UTC](https://discourse.slimframework.com/t/404-routing-and-javascript-frameworks/585/2 "2016-08-05T22:36:00Z")

</div>

I found a solution. The following will override `notFoundHandler()` which is triggered by a 404 and instead load a route without redirecting the user:

```
$container['notFoundHandler'] = function(\Slim\Container $container) {
    return function(\Slim\Http\Request $request, \Slim\Http\Response $response) use ($container) {
        return $container->router->getNamedRoute('index')->run($request, $response)->withStatus(404);
    };
};
```
