I want to show 404 error page, but also I want to save wrong url in location.
If I'll do something like that:
$urlRouterProvider.otherwise('404');
$stateProvider
.state('404', {
url: '/404',
template: error404Template
});
url will change to /404
. How I can show error message on wrong urls without changing actual url?
As of
ui-router#0.2.15
you can use$state.go()
and send option not to update the location:There is solution for this scenario. We'd use 1) one
ui-router
native feature and 2) one configuration setting. A working example could be observed here.1) A native feature of ui-router state definitions is:
2) A configuration setting is:
otherwise()
for invalid routes, which parameter does not have to be a string with default url, but could be a function as well (cite):Solution: combination of these two. We would have
state
withouturl
and customotherwise
:Check that all in this working example