question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fix(router): wildcard routes with redirects

See original GitHub issue

As of alpha 36 there is no otherwise route condition. The use case is where you want an invalid route or set of routes to either go to specific route or run a function that can do custom logic and re-route.

As another option for simple redirection, I would expect this to work, but it does not

@RouteConfig([
  { path: '/*', redirectTo: ROUTES.heroes }, //TODO: Need an otherwise in some way
  { path: ROUTES.about, as: 'about', component: AboutComponent },
  { path: ROUTES.heroes, as: 'heroes', component: HeroesComponent },
  { path: ROUTES.detail + '/:id', as: 'detail', component: HeroDetailComponent }
])

I’m requesting both an otherwise and the * pattern above to work.

cc // @btford

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
ericmartinezrcommented, Jun 30, 2016

@jakegraves

{path : '**', component : SomeComponent} // or redirectTo : '/404'

Sorry, from top of my head, don’t remember exactly. You can come to gitter to ask https://gitter.im/angular/angular you’ll find someone who knows

2reactions
slayerfatcommented, Jul 13, 2016

The router documentation and the cheat sheet IMHO should say something about @ericmartinezr solution

Read more comments on GitHub >

github_iconTop Results From Across the Web

Wildcard route is not working every route is being redirected
In angular routing I have added this logic for invalid URL since then every route is being considered as invalid route
Read more >
Default, Redirect and Wildcard Routes - AngularDart
As an alternative solution, remove the useAsDefault argument that you just added, and instead add a redirect route that will translate an initial...
Read more >
Wildcard Routes (**) Can Redirect Relative To Their UrlTree ...
As a quick follow-up post, I wanted to demonstrate that a wildcard route can redirect to a URL that is relative to its...
Read more >
Angular 9/8 How-To: Path Redirection and Handling 404 ...
Internally, the router uses a function called applyRedirects to process redirects. Step 5 - Handle 404 (not found pages) using wildcard paths.
Read more >
next.config.js: Redirects
Redirects are not applied to client-side routing ( Link , router.push ), unless ... To match a wildcard path you can use *...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found