ways icon indicating copy to clipboard operation
ways copied to clipboard

retrieving the current request "state" ?

Open hems opened this issue 10 years ago • 3 comments

How can i retrieve the state associated with a request?

For instance:

ways = require( "ways" )
ways( "/save", function( req ) {

  console.log( "How to retrieve the state object here?", req );

} );
ways.go( "/save", "", { hi: true } )

hems avatar Dec 24 '15 00:12 hems

Good one, I wonder how it never popped out before. :smile:

Ideally it should be:

ways( "/route", function( req, params, state ) {
  // ...
} );

However it should be done, pull requests wellcome.

In this meanwhile, you can do something:

  1. Here you find the start point for this behavior
  2. It leads you here or here, depending on what your are using (hash x history).
  3. Regardless, we found ourselves here at this point, where we can dig the history array:
// pseudo code here (not tested)
var addressbar = require('ways-addressbar');
ways.use(addressbar);
ways( "/route", function( req ) {
  console.log(addressbar.history);
} );
ways.go('/route', {hi: true});

Something should be there. :)

arboleya avatar Dec 24 '15 14:12 arboleya

i'm not using addressbar.... in that case ?

hems avatar Dec 24 '15 16:12 hems

In this case, following the frist link I've sent, in you're here, without history / pushstate.

You can do a plugin and make it handle state/history for you, the basics are also covered in the tests in case you wanna take a look.

arboleya avatar Dec 24 '15 17:12 arboleya