0

So, I have a single page angular app that is opened when I navigate to a URL. If I use the links, moving around within the app is fine - new URLs load just fine. However, if I enter a new URL in the browser URL window and hit enter, the back end framework - Laravel in my case - tries to resolve the URL.

How do I either

  1. Intercept the URL change so that I can simple direct it to the appropriate state in the app

  2. Tell Laravel to ignore the new URL and let the angular app handle it

Thanks

1 Answer 1

2

If I understand your question correctly, you don't want Laravel handles it because the routes is defined in javascript, not in server side. If that's the case, you can simply solve it by using wildcard.

Let's say in your laravel's routes you have this line to load your app, views, javascripts etc:

Route::get('/', 'PagesController@index');

You can use the wildcard modifier to ignore whatever url that has appended, and always serve your index view instead:

Route::get('/{any?}', 'PagesController@index')->where('any', '.*');

I'm not sure why it's not in the latest documentation, but you can find the docs at Laravel 5.2 doc regarding regular expression constraints

Sign up to request clarification or add additional context in comments.

3 Comments

Interesting. Will that still reload the page?
This seems to be working for me. Thanks a ton. I didn't initially realize that you could have any regular expression in the where statement.
They didn't put it up in the docs though, I hope they don't deprecate it since it's a critical feature :)

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.