angularjs - angular $routeProvider with html5 -


i have problem $routeprovider when use html5mode correctly. when access /profile/: child fine, when page refreshed, on page errors. there wrong code below:

app.config(function ($routeprovider, $locationprovider) {  var pathviews = function (file) {     return 'http://localhost/mycompany/app/views/' + file; }; var patherror = function (file) {     return 'app/views/error/' + file; }; $locationprovider.html5mode(true); $routeprovider     .when('/', {         templateurl: pathviews('dashboard.html'),         controller :'mainctrl'     })     .when('/home', {         templateurl: pathviews('dashboard.html'),         controller :'mainctrl'     })     .when('/profile/:child', {         templateurl: function($routeparams) {             return pathviews($routeparams.child+'.html')},                 controller:'mainctrl'     })     .when('/404', {         templateurl: patherror('404.html'),         controller :'mainctrl'     })     .when('/form-standard', {         templateurl: pathviews('form-standard.html'),         controller :'mainctrl'     })     .otherwise({redirectto: '/404'});}); 

and index.html is: <div ng-view ></div>

this normal since when refresh page web server tries load requested resource doesn't exist on server instead handled on client side.

for example,if deploy "routeprovided" angularjs application on apache, should edit .htaccess (source):

rewriteengine on  # don't rewrite files or directories rewritecond %{request_filename} -f [or] rewritecond %{request_filename} -d rewriterule ^ - [l]  # rewrite else index.html allow html5 state links rewriterule ^ index.html [l] 

in plain english, have tell web server redirect every request main module entry point.


Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -