Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS routing with direct url

Tags:

angularjs

I'm having trouble with the routing, it's all works fine when I route between pages using <a href="/someurl"> on the page.

When I input the link directly into the browser with the # like http://localhost/#/someurl it works fine also.

But if I enter it without the # like http://localhost/someurl I get Cannot GET /task/2

I'm using the HTML5 mode in angular $locationProvider.html5Mode(true); The backend is Web API build with MVC4 C# so only routing is controlled with app.js (angular)

like image 964
ArniReynir Avatar asked Apr 08 '26 11:04

ArniReynir


1 Answers

If you want to use the $locationProvider's html5Mode, you'll have to couple it with some server tweaks so that your web server knows to serve up the same content regardless of path.

If you're using Apache for example, you can use mod_rewrite.

like image 96
Langdon Avatar answered Apr 11 '26 14:04

Langdon