javascript - $stateprovider throws 404 if i visit link directly from url bar -
i'm using ui.router angularjs , came across strange behavior. if click trough page works expected, links changing, templates loading, if visit specific page directly (other www.myapp.com) 404 page not found
this app.js
var app = angular.module('app', ['ui.router', 'ui.bootstrap']); app.config(function($stateprovider, $urlrouterprovider,$locationprovider){ $urlrouterprovider.otherwise("/dashboard"); $stateprovider .state('dashboard', { url: "/dashboard", templateurl: "app/templates/dashboard/dashboard.html", controller: 'dashboardctrl' }) .state('locations', { url: "/locations", templateurl: "app/templates/locations/locations.html", controller: 'locationsctrl' }) .state('locations.add_location', { url: "/locations/add_location", templateurl: "app/templates/locations/add_location.html", controller: 'addlocationctrl' }); $locationprovider.html5mode(true); });
explained in pictures
i visit www.myapp.com, page renders
click on locations, working
can click on dashboard link again , work
but if press f5 or copy paste link in url bar of browser, 404
why happening. im missing. if need additional informations, please let me know , provide.
that's because apache tries serve file location
in www root directory. it's not possible because have got spa app without subpages. have force apache web server rewrite locations , serve index.html
page (main page). found helpful gist that: https://gist.github.com/santthosh/7dabf08fa3859361ef1e
Comments
Post a Comment