Giter Club home page Giter Club logo

Comments (1)

millermedeiros avatar millermedeiros commented on July 20, 2024

Yes, it will be hard to implement, the addRoute adds the callback to the Route.matched Signal, the return value from the callback will be used to stop the signal propagation if false (source) so we can't really use it's value (specially since each signal can have multiple handlers).

The way to do it is to store the value into some variable/property and retrieve it later.

Depending on your need I would probably centralize this logic into a single handler on the crossroads.routed signal:

var _currentSection;

var _news = crossroads.addRoute('/news/{id}');
var _foo = crossroads.addRoute('/foo/{bar}');

// here we listen to any route so we can do our "magic"
crossroads.routed.add(registerCurrentRoute);

// naive implementation, if you have many diff routes abstract this logic
// or add your own custom properties to the Route object to simplify it
// eg: `_news.id = "news"` ...  `_currentSection = data.route.id`
function registerCurrentRoute(request, data){
   if (data.route === _news) {
      _currentSection = 'news';
   } else if (data.route === _foo) {
      _currentSection = 'foo';
   } else {
     _currentSection = null;
   }
}

Closing this for now since it's working as designed and I don't think this feature would scale for multiple handlers (and there are workarounds).

from crossroads.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.