0

Im at the moment building an application where i want my urls to be like my-domain.com/ instead of my-domain.com/#/. Because I'm building an SPA with AngularJS, I enabled the html5Mode of the $locationProvider.

However, when i go to another page like my-domain.com/test (defined in my $routeProvider config), I get laravel's error page. This is not what i want because i want AngularJS to handle this route.

I looked around and found things like

App::missing(function($exception)
{
    return view('client/index');
});

which sadly dont work in Laravel 5. After researching the new way to handle errors, I decided to test the new Exception Handler, so in my App\Exceptions\Handler.php I did this:

public function render($request, Exception $e)
    {
        return view('client/index');
    }

Unfortunately, this also doesnt work because now it renders a blank page...

Does anyone have an idea how to fix this? Here is my code of my angular ngroute config:

client.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider){
    $routeProvider
        .when('/', {
            templateUrl: '/client_partials/Homepage.html'
        })
        .when('/test', {
            templateUrl: '/client_partials/Homepage.html'
        })
        .otherwise({
            redirectTo : '/'
        });

    $locationProvider.html5Mode(true);
    $locationProvider.hashPrefix('!');
}]);
1
  • 1
    reconfigure your htaccess so any non asset or api requests are pointed to app entry point Commented Feb 23, 2015 at 19:17

1 Answer 1

7

Here is the route:

Route::any('{path?}', function()
{
    return File::get(public_path() . '/angular.html');
})->where("path", ".+");
Sign up to request clarification or add additional context in comments.

2 Comments

This will cause the page to refresh, totally negating any benefit of a single-page JS app. You can achieve this with .htaccess, no other routes are necessary.
This worked for me, except I use view() to present the view, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.