Answer the question
In order to leave comments, you need to log in
How to properly fix 404 error when updating states?
Good afternoon!
I am using angular-ui-router to create navigation. The application launches and all links work fine until the refresh button in the browser is clicked. In this case, there will be a 404 error on the site/view route . Can you please tell me if this can be fixed somehow other than setting it up via .htaccess?
JS:
var myApp = angular.module('myApp', ['ui.router'])
.run(['$rootScope', '$state', '$stateParams',
function ($rootScope, $state, $stateParams) {
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
}
]);
myApp.config(function($stateProvider, $urlRouterProvider, $locationProvider) {
$urlRouterProvider.otherwise('/view');
$stateProvider
.state('view', {
url: '/view',
templateUrl: 'views/view.html',
controller: ['$scope', '$state',
function ( $scope, $state) {
}]
});
$locationProvider.html5Mode(true);
});
<base href="/">
....
<nav>
<ul>
<li ><a href="#" ui-sref="view">Просмотр</a></li>
</ul>
</nav>
<div>
<ui-view>
</ui-view>
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question