excess-router
excess-router copied to clipboard
Is there a way to have params in redirects?
Let's say I want to rename a route with params, but make sure that any existing old links work. e.g.
<excess-route
route-alias="room"
route-params="{{pageParams.room}}"
route="/room/:id?"
redirect-to="/space/:id"
></excess-route>
<excess-route
route-alias="space"
route-params="{{pageParams.room}}"
route="/space/:id?"
></excess-route>
So old links that used to go to /room/123 would get redirected to /space/123
Is that possible?
Good question. You can't do it using excess-route element, but it is easily done in Javascript:
Excess.RouteManager.register('/room:id', {
willActivate: function(transaction, routeParams) {
transaction.abort( {
redirectTo:'/space/' + routeParams.id;
});
});
What you are doing here is aborting a route transaction with a redirect.
My syntax might be slightly off, I have not commented this well.
Thanks, works well! Here's the more precise syntax if anyone finds this and wants to copy/paste:
Excess.RouteManager.register('/room:id', {
alias: 'room',
willActivate: function(transaction, params) {
transaction.abort({
redirectTo: '/space/' + params.routeParams.id
});
}
});
:+1: