AlexGalays/abyssa-js

Relative navigation

Closed this issue · 1 comments

Is there any plan to support relative navigation?

It would be super useful when a parent need to reroute between several children but you don't want to rely on the full name, just the fact that it's child A or child B. The other obvious use case is to go to the parent.

I'm pretty sure we can already do something close using Router.currentState() and names, but it would be cool to have it natively in Abyssa.

Inspiration : https://github.com/angular-ui/ui-router/wiki/Quick-Reference#examples-diagram

// Currently, we can do:
// (assuming you have Lodash, otherwise, write your own merge)
Router.siblingState = function siblingState(childName, params) {
  var currentState = Router.currentState();
  var names = currentState.fullName.split('.');
  names.pop();
  names.push(childName);
  Router.state(names.join('.'), _.merge(params || {}, currentState.params));
};

// Go to 'articles.all' -> /articles
Router.state('articles.all');

// Go to 'articles.detail', {id: 1} -> /articles/1
Router.siblingState('detail', {id: 1});

// Would be could to support the syntax:
Router.state('^.detail', {id: 1});

This functionality seems fun and all, but not all that useful. I'm in the process of trimming the router API and I would like to only keep core functionalities in.