AngularJS Ui Router regex matching pattern in url

I wonder if this is possible - I need to map the following URLs to a single pattern:

/one/app/home
/one/two/app/home
/one/two/three/app/home
...

I understand that AngularJS routing does not support regex, but Angular UI Router does.

main.config(function($stateProvider, $urlRouterProvider, $locationProvider) {
    $urlRouterProvider.otherwise("/fail");
    $stateProvider
    .state("home", {
        url: "{.+}/app/home",
        templateUrl: "assets/tpl/home.html",
        controller: "homeController"
    })
    $locationProvider.html5Mode(true);
});

This does not work (goes /failwith all the examples). Is that what I want to do at all?

+4
source share
1 answer

You should use it as follows:

state("home", {
    url: "/{beginPath:.+}{endPath:/app/home}",
    templateUrl: "assets/tpl/home.html",
    controller: "homeController"
});

$stateParams.beginPath ( evertyhing /app/home/) $stateParams.endPath, /app/home/

/one/ , - :

url: "/{beginPath:one/.+}{endPath:/app/home}"
+6

Source: https://habr.com/ru/post/1536939/


All Articles