Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

partial static routing parameter angular 2

Is it possible to use a partial-static parameter in angular 2 routing? I'm going to explain:

Now I'm using classic parameter like this:

const routes: Routes = [
  {
    path: ':type/fine.html',
    pathMatch: 'full',
    redirectTo: ':type/fine'
  }

But I would be able to use something like this:

const routes: Routes = [
      {
        path: 'static-:type/fine.html',
        pathMatch: 'full',
        redirectTo: 'static-:type/fine'
      }

To be able to redirect exactly to static-{{parameterValue}}/fine.

Is it possible?

like image 398
Luca Taccagni Avatar asked Mar 02 '18 11:03

Luca Taccagni


People also ask

What is NavigationExtras in Angular?

Passing data between the Angular component through the route is very easy after the release of the Angular 7.2 version. NavigationExtras provides an easy way to pass data from the template and from the component. Small components are always good to manage code maintainability.

What is ActivatedRoute in Angular?

What is an activated route? The Angular Docs define the ActivatedRoute as. A service that is provided to each route component that contains route specific information such as route parameters, static data, resolve data, global query params and the global fragment.

What is the use of pathMatch in Angular?

pathMatch = 'prefix' tells the router to match the redirect route when the remaining URL begins with the redirect route's prefix path. pathMatch: 'full' means, that the whole URL path needs to match and is consumed by the route matching algorithm.


1 Answers

After many tries i've reached the knowledge that is impossible to do something like it. So i've implemented a completely different approach with a routing-guard following this example:

http://www.sparkbit.pl/angular-2-route-guards-real-life-example/

Just answering for anyone who will find same problem.

like image 57
Luca Taccagni Avatar answered Sep 21 '22 00:09

Luca Taccagni