Giter Club home page Giter Club logo

Comments (5)

tj avatar tj commented on June 29, 2024

page.replace() should work fine for this if you dont want it in the history since the user didn't navigate there

from page.js.

ericfong avatar ericfong commented on June 29, 2024

Hi, I may miss something. Please forgive me if I am wrong.
My problem is

page('/default', function(context, next){
    console.log('Default');
})
page('/', function(context, next){
    // redirect to '/default'
    page('/default');
})
page();

I expect that will finally print 'Default' and Url changed to '/default'

But I found:

  1. page();
  2. call page.start();
  3. call page.replace(location.pathname + location.search);

Let say location.pathname + location.search = '/'

  1. page.replace create ctx and ctx.canonicalPath= '/'
  2. page.replace call page.dispatch in https://github.com/visionmedia/page.js/blob/master/index.js#L143
  3. page.dispatch call my own redirect code (which expect page('/default') can redirect the url)
  4. page('/default') redirect URL to '/default'

However, after https://github.com/visionmedia/page.js/blob/master/index.js#L143

  1. call ctx.save()
  2. that ctx.canonicalPath= '/'
  3. ctx.save() call history.replaceState
  4. replaceState replace '/default' back to '/''

Don't know whether it is a feature or we should have some other code to do redirection?

from page.js.

tj avatar tj commented on June 29, 2024

ah yeah I remember now the deferred ctx.save(). We need a flag to indicate that we shouldn't save if page() has been called in the same tick or something, I'll take a look, for now you can just defer with setTimeout 0 or setImmediate and it'll work fine

from page.js.

ericfong avatar ericfong commented on June 29, 2024

Already flip them in here ericfong@6a920fd

But I don't think I have consider all situations, so I just keep it in my own repo.

from page.js.

A avatar A commented on June 29, 2024

closed with #140

from page.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.