R
R
Ruslan2017-05-16 20:58:37
Angular
Ruslan, 2017-05-16 20:58:37

Angular 1.x How to make $routeProvider ignore links with "#" stubs?

Dropdown menu issue from Bootstrap. When you click on the dropdown, the menu item joxi.ru/n2YkVqquo46Bzr triggers the rule otherwise

$locationProvider.hashPrefix('!');
$routeProvider.otherwise({redirectTo: '/main'});

and accordingly shows the view of the main page.
There is a stub in the dropdown link. href="#"
How can I overcome this and force stubs to be ignored? Will have to use also sliders, there will be the same problem...
angularjs angular-routing

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Philipp, 2017-05-16
@habruff

You need to listen to the $routeChangeStart event and cancel the action.

$rootScope.$on('$routeChangeStart', function(event, next, current) {
 // добавьте здесь свою проверку на пустой hash и вызовите отмену 
  event.preventDefault();

});

I recommend to carefully read https://docs.angularjs.org/api/ngRoute/service/$route

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question