Create advanced route in Angular.js

Asked

Viewed 878 times

-1

I’m trying to get my router, work a little differently. Today he is like this, for example:

$routeProvider.
when('/cliente', {
    templateUrl: '/cliente',
}).
when('/login', {
    templateUrl: '/usuario/login',
}).
when('/home', {
    templateUrl: '/home/home',
}).
when('/unauthentication', {
    templateUrl: '/utils/unauthentication',
}).
otherwise({
    redirectTo: '/home'
});

That’s correct, but I would like a behavior that when passing this route, for example: #/cliente/data, If he can’t find it, he’ll only look for it #/cliente, and then if I didn’t, I’d go to the otherwise.

What I would like is something like this, for example:

$routeProvider.
when('/cliente/get', {
    templateUrl: '/cliente',
}).
// esses '...' não existe, só utilizei para representar qualquer coisa
when('/cliente/...', { 
// aqui pegando tudo que iniciar com /cliente, menos /cliente/get que é uma rota especifica
    templateUrl: '/cliente',
}).
otherwise({
    redirectTo: '/home'
});

It would be a logic similar to the following:

Date the next route: #/foo/blah/blah2/foo2;

  1. I would try the original route: #/foo/blah/blah2/foo2;
  2. Would try the route: #/foo/blah/blah2;
  3. Would try the route: #/foo/blah;
  4. Would try the route: #/foo;
  5. Then I’d go to the otherwise;

Questions

  • Is there any way to configure the $routeProvider for that reason?
  • Or is there some extension of route Angular.js standard that can use? And how would I use it to achieve this outworking?
  • take a look here: https://docs.angularjs.org/api/ngRoute/service/$route#example in the tab script js. has an example similar to yours, maybe it will serve

  • @luigibertaco, not quite what I need, there in this case is an example of how to prepare the routes to receive parameters, I’ve been researching a little more and I was seeing that this route (native) angular is a bit limited and I’m analyzing other route third party to Angular. Still thanks for the availability in helping.

1 answer

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.