New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Route redirectTo as function / class #13373
Comments
|
You can redirect in the CanActivate guard, can't you ? |
|
Yes, and that's the approach I took. However, I feel that mentally separating redirect and guards is a lot more easy to reason about. Also, using the guard approach, the route still needs a component , children or redirectTo defined. If there would be no problem, I would be open to implementing it using the same pattern as the |
|
@vicb
const routes: Routes = [
{ path: '', canActivate: [RedirectGuard] }
];There is no error when I have a bit of advanced use case. The app I'm working on has |
|
This would also be great for my project as well. In the simplest case, I would be happy to have redirectTo be a function that can take an ActivatedRouteSnapshot and a RouterStateSnapshot as arguments. I'm using this to support a structure like this: We used a structure like this for our AngularJS app with UI-Router, and it worked very well. I would love to be able to mimic that in Angular. |
|
I know this already is quite old. But I'm in the same situation. I want to redirect from an empty route to another route with dynamic params. Now I have to do this Which is a little ugly and looks like I'm abusing the system. |
|
According to this article, Better Redirects in Angular Route Guards, since Angular 7 it is allowed to return an |
My Code : app-routing.module.ts : tracker-routing.module.ts : Expected Behaviour When App Loaded for 1st time (URL) : Actual Behaviour Now What I am getting for 1st time App Loading (URL): http://localhost:4200/tracker Can Anyone Please help me to Understand this Concept, like why this is happening and how to resolve this. Thank You very Much. :) |
|
Maybe making route.paramMap mutable would be enough: DynamicResolver : but |
… redirectTo Redirects in the router are processed before activations. This means that a canActivate will never execute if a route has a redirect. Rather than silently ignoring the invalid config, developers should be notified so they know why it doesn't work. Closes angular#18605 The feature request for a function/class redirect is covered in angular#13373.
… redirectTo Redirects in the router are processed before activations. This means that a canActivate will never execute if a route has a redirect. Rather than silently ignoring the invalid config, developers should be notified so they know why it doesn't work. Closes angular#18605 The feature request for a function/class redirect is covered in angular#13373.
… redirectTo (#40067) Redirects in the router are processed before activations. This means that a canActivate will never execute if a route has a redirect. Rather than silently ignoring the invalid config, developers should be notified so they know why it doesn't work. Closes #18605 The feature request for a function/class redirect is covered in #13373. PR Close #40067
|
I have been using the solution like @SamVerschueren wrote for years now. But since angular 14 it's not possible to use pathMatch="full" and a dynamic direct function any more without adding a useless component (read unused/dummy). |
|
@egonknapen just faced with the same issue but it seems that adding |
Thanks, I tried using children, but I couldn't imagine what to put in it, didn't think about leaving it just empty. So now we got 2 so called hacks [canActivate] + 'children:[]', to get dynamic routing working. I would suggest angular comes up with their own solution or add the preferred way to their documentation. |
Same here. It seems weird that an empty children array passes validation, but leaving children out does not. Reading this thread it seems that |
I searched in the internet, and found a few articles all describing the same way. So I think it's up to the angular developers, to add their preferred way. It's a valid use case, to want a dynamic routing. If they don't I'm afraid, next time they will come up with another way to prevent us from doing just that. Of all the components of angular I have been using, the routing had been the most limiting (read less happy with). For example I wish it was more easy to use matrix variables, even when you don't want navigation to happen, for example if you are using tabs, and want the current tab as a matrix variable, so when copy&pasting the url, it will open on the same page. (But that's outside the scope of this bug-issue) |
|
I have a scenario where different users have a different landing page after sign in. The default landing page is set in the redirectTo but this now needs to become dynamic to accommodate for the different user types. For example:
Would be helpful if redirectTo can be structured like canActivate and we can access the ActivatedRouteSnapshot. |
|
We have a similar use case when a user goes to @epelc I disagree, I used the error message to find this thread as I updated Angular and it was pretty easy. |
I personally have the opinion that both are only hacks. I better solution would be something like [RedirectTo] with a function/method behind it. So it would be directly clear, that this function would specify the direct. But as often I get to hear, it's not in the documentation, it's not planned, end of discussion. But then there are hacks to fix what is missing, until the next time, when they close a way around the problem. We will see, probably need to make a feature request, and then get at least 20 people to vote for it. But for that we need to wait, we only got 15 people now, watching this. |
|
Just a quick update: I do believe this is a high priority item for the Router. There are some questions that I don't have answers to at the moment but don't have time to fully think about due to other items that are higher priority. Maybe discussions in this issue can explore these and come to a satisfactory answer:
|

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.


I'm submitting a ... (check one with "x")
What is the motivation / use case for changing the behavior?
Currently, in a
Routedefinition,redirectTocan only be a string.In order to provide higher flexibility, it could also be a object, like theRezolve.The advantages related to the control we can have over the route parameters and the queryParams, or even dynamic redirection
The text was updated successfully, but these errors were encountered: