-
Notifications
You must be signed in to change notification settings - Fork 595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: Programatic navigation #85
Comments
Hey @josephg, we were just talking about this (see #21). It looks like the best way may be to use the native DOM API ( |
If we can pull it off, perfect. I tried that first hoping it would automatically work. Thanks! |
@josephg Did you end up resolving this - can this be closed? |
Well if thats the intended behaviour, it doesn't work yet: const choo = require('choo');
const app = choo();
const nav = (url) => {
console.log('nav to', url);
window.history.pushState(null, null, url);
}
app.router((route) => [
route('/', (params, state, send) => choo.view`
<button onclick=${() => nav('/foo')}>Nav</button>
`),
route('/foo', (params, state, send) => choo.view`<h1>Somewhere else</h1>`)
]);
document.body.appendChild(app.start()); ... The button changes the URL but the new route isn't rendered. |
|
@timwis: That forces an unnecessary full page re-render, which I'm trying to avoid. |
Also @yoshuawuyts: Taking a look at the browser's API, I don't think there's any way for the framework to find out when From MDN:
So for simple navigation, |
@josephg you're right - labelling this a bug; we should fix this |
So what would the appropriate fix be? If someone changes the window.location, are you saying we need to let choo know somehow? I would prefer that this is done manually, or at least by somehow setting up a subscription to the window. At anyrate, can someone explain what the problem / intended result should be? I'm not clear on the issue, the original post actually seems like a reasonable approach to me and it doesnt look like a bug. So I must be reading this wrong. |
@MattMcFarland It's not a bug. It's a feature request to make it possible to change the location with a single API call (e.g. |
@mantoni Yes thank you! Is this a feature we are going to add? If so I could work on this providing nobody else is. I"m just looking for something to do :) |
@MattMcFarland I saw that @yoshuawuyts was looking into it recently and concluded that this would be a breaking change (see his last comment here). |
[oops mispasted comment, moved it to https://github.com//issues/65#issuecomment-236914727] |
Yup I think this should all work now in |
I've ended up using this action to navigate between pages:
It'd be nice if there was an officially recommended way to do it. (This or something else.)
The text was updated successfully, but these errors were encountered: