Comments (5)
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.
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:
- page();
- call page.start();
- call page.replace(location.pathname + location.search);
Let say location.pathname + location.search = '/'
- page.replace create ctx and ctx.canonicalPath= '/'
- page.replace call page.dispatch in https://github.com/visionmedia/page.js/blob/master/index.js#L143
- page.dispatch call my own redirect code (which expect page('/default') can redirect the url)
- page('/default') redirect URL to '/default'
However, after https://github.com/visionmedia/page.js/blob/master/index.js#L143
- call ctx.save()
- that ctx.canonicalPath= '/'
- ctx.save() call history.replaceState
- 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.
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.
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.
closed with #140
from page.js.
Related Issues (20)
- 'prevContext' on hash change not set properly
- bug for omitting query and hash from pathname
- Page reload on redirect page("./pageToRedirect") HOT 1
- Doesn't work with Github Pages? HOT 1
- page.len does not decrease after click browser's back button
- Relative link when current location has #hash triggers a reload while it doesn't with no #hash or empty # HOT 3
- can't access ctx.page.preContext, ctx === ctx.page.preContext returns true
- very simple page, but got 404 HOT 1
- page('/about', about); HOT 1
- What NPM Package should I use? "page" or "page.js" HOT 1
- Page base not used for history state (breaks reloading in electron) HOT 2
- Handling onpage hash links HOT 5
- It would be nice to have a minified version available
- Change route url without refreshing HOT 1
- Whether pathname includes base depends on whether there is an anchor (#foo)
- doc link 404
- Browser back/Forward button with saved warning message HOT 2
- history.state is cleared on initial page load
- is this project still active? HOT 8
- Worth forking? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from page.js.