aurelia / router

A powerful client-side router.
MIT License
120 stars 115 forks source link

Dynamic redirect route handler #585

Open valichek opened 6 years ago

valichek commented 6 years ago

I'm submitting a feature request

Having possibility to redirect from route handler would be a nice feature For example sometimes I need redirect with some logic. This could look like following:

{ route: '', redirect: (params, navigationInstruction) => {
    return Promise.resolve(new Redirect('new-path')) // or return new Redirect('new-path'), or 'new-path'
} },

Current behavior:

Now it's possible to handle redirect in modelView handlers like canActivate(). So I need to create dummy module and place redirection logic to canActivate().

davismj commented 6 years ago

@valichek can you give me a real example? It seems like it could be useful but I can't think of a valid use case.

valichek commented 6 years ago

@davismj real use case: we have ACLs, child router is configured with all possible routes, navigation menu is filtered according to ACL, user can switch role any time, depending on role default route in child router can be different.

valichek commented 6 years ago

@davismj another use case, consider we want to handle /shop/SHOP_ID/admin route and redirect to /user/USER_ID/profile. This is not good example from app side, but shows ability to "convert" links

davismj commented 6 years ago

@valichek and AuthorizeStep doesn't solve this use case?

valichek commented 6 years ago

@davismj AuthorizeStep is good only for AppRouter, but not for its childRouters

ItWorksOnMyMachine commented 4 years ago

We have routes that look like '/clients/module' and want to change to '/clients/:clientId/module' but we have a lot of places where the old routes still exist (emails we sent, user's bookmarks, etc.) that are beyond our control. The solution proposed here would help us to create a dynamic redirector that would capture any navigation event to the old URL, inspect the current user's state information, and redirect to the new url with the :clientId parameter in place.