excess-router icon indicating copy to clipboard operation
excess-router copied to clipboard

Is there a way to have params in redirects?

Open semateos opened this issue 9 years ago • 3 comments

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?

semateos avatar Mar 07 '16 20:03 semateos

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.

atotic avatar Mar 08 '16 04:03 atotic

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
      });
    }
  });

semateos avatar Mar 08 '16 19:03 semateos

:+1:

atotic avatar Mar 08 '16 20:03 atotic