1

I'm using @angular/router @ version 2.0.0-rc.1

I can't seem to get wildcard parameters working, and from reading the code it seems there is no support.

2
  • 1
    It will be added with one of the next versions. Commented May 29, 2016 at 13:36
  • Cool, will continue with @angular2/router-deprecated for now Commented May 30, 2016 at 10:48

2 Answers 2

3

With the Angular 2.0.0 (final release) and the new router you can normally use wildcards, now paths are being used without slash.

NOTE:
the order of the routes matters: it should go from the most specific to the least specific. So as for the simple example below, the route '**' (matches anything) should be put at the end, so all the other possible routes would be covered by the previous ones.

const routes: Routes = [ { { path: 'login', component: LoginComponent }, { path: 'register', component: RegisterComponent }, { path: '**', component: LoginComponent }, ]; 
Sign up to request clarification or add additional context in comments.

Comments

1

You can do like this in app.ts

import {Home} from './Home'; ... @RouteConfig([ { path: '/home', component: Home, name: 'Home' }, { path: '/**', redirectTo: ['Home'] } ]) 

In this example,we only have one real route set up, and that is the /home route. We are also instructing the app to redirect any request to unrecognized routes to the Home component. Each RouteDefinition requires a path, a name, and either a component, loader, or redirectTo.

3 Comments

this example is using the old router though, right? (You have @RouteConfig, plus I see no handling of ** specifically in github.com/angular/angular/blob/master/modules/@angular/router/…)
This is Angular2. You can read about it on this blog. auth0.com/blog/2016/01/25/…
Angular2 also has an old router ;-). With RC.0 a new router was introduced. The old router is available as router-deprecated. Your example clearly uses router-deprecated because in the new router there is no name argument anymore.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.