Slim $app->redirect Issues

I am having some issues with the $app->redirect() method. I am using trying to redirect to a new page when a form submission goes through successfully. I am getting this error:

Type: BadMethodCallException
Message: Method redirect is not a valid method
File: C:\wamp\www\endesign\vendor\slim\slim\Slim\App.php

contact.twig code:

{% extends 'base.twig' %}

{% block content %}
	<div class="col-xs-12 col-md-8 col-md-offset-2">
		<form actions="index.php" method="post">
			<input name="name" type="text" placeholder="Full Name">
			<input name="email" type="email" placeholder="Email Address">
			<textarea name="message" placeholder="Enter your message here..."></textarea>
			<input class="button" type="submit" value="Send Message!">
{% endblock %

index.php code:


use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

require 'vendor/autoload.php';

$config = [
    'settings' => [
        'displayErrorDetails' => 1,

$app = new \Slim\App($config);
$container = $app->getContainer();

// Register component on container
$container['view'] = function ($container) {
    $view = new \Slim\Views\Twig('templates');
    $view->addExtension(new \Slim\Views\TwigExtension(
    return $view;

$app->get('/', function ($request, $response, $args) {
    return $this->view->render($response, 'home.twig');

$app->get('/about', function ($request, $response, $args) {
    return $this->view->render($response, 'about.twig');

$app->get('/services', function ($request, $response, $args) {
    return $this->view->render($response, 'services.twig');

$app->get('/portfolio', function ($request, $response, $args) {
    return $this->view->render($response, 'portfolio.twig');

$app->get('/contact', function ($request, $response, $args) use($app) {
    return $this->view->render($response, 'contact.twig');

$app->get('/photography', function ($request, $response, $args) {
    return $this->view->render($response, 'photography.twig');

//SwiftMailer for Contact Page

$app->post('/contact', function(Request $request, Response $response, $args) use($app) {
	$name = $_POST['name'];
	$email = $_POST['email'];
	$message = $_POST['message'];
	if (!empty($name) && !empty($email) && !empty($message)){
		$cleanName = filter_var($name, FILTER_SANITIZE_STRING);
		$cleanEmail = filter_var($email, FILTER_SANITIZE_EMAIL);
		$cleanMessage = filter_var($message, FILTER_SANITIZE_STRING);
	} else {
	$transport = Swift_SmtpTransport::newInstance('', 465, 'ssl')
	$mailer = \Swift_Mailer::newInstance($transport);
	$message = \Swift_Message::newInstance();
	$message->setSubject('New Email');
		$cleanEmail => $cleanName
	$result = $mailer->send($message);
	if($result > 0){
	} else {

// Run app

I’m not entirely sure what I am doing wrong here. Does anyone have any insight for me?

Thank you in advance

If anyone else has this issue I have figured it out. Below is the code where the redirect comes in to play, which happens when the form submission is successful.

	if($result > 0){
		return $response->withRedirect($router->pathFor('home'));
	} else {
		return $response->withRedirect($router->pathFor('contact'));