page.js icon indicating copy to clipboard operation
page.js copied to clipboard

weird infinite loop issue

Open robdodson opened this issue 10 years ago • 3 comments

If I set page({ hashbang: true }); before setting up my routes, the router gets stuck constantly refreshing the same page.

ex:

// Broken
page({ hashbang: true });
page('/', home);
page('/portfolio', portfolio);
page('/contact', contact);
// Works
page('/', home);
page('/portfolio', portfolio);
page('/contact', contact);
page({ hashbang: true });

It seems like the router should be tolerant of setting configuration before defining the routes, unless there's a specific reason why you wouldn't want to do this?

robdodson avatar Feb 12 '15 03:02 robdodson

Adding Page.js to a site I'm working on and ran into the same thing. @robdodson Thanks for the examples for // Broken and // Works. Especially the latter. :-)

QueueHammer avatar Mar 04 '15 05:03 QueueHammer

Ditto; this was causing me so much trouble today switching from "more-routing" to "page.js". I feel like setting up the "page( config )" stuff should happen first, and I never would have tried to set it at the end.

tekkamanendless avatar Dec 20 '15 05:12 tekkamanendless

page(options) is the same as page.start(options). So while you think are configuring page you really are starting it, in which case not having routes defined is a problem.

For 2.0 (or perhaps before) I'm thinking about adding a page.configure(options) so you can more explicitly say (I want to configure page.js now) and it doesn't matter if you have routes defined or not.

So yeah, confusion is caused because configuring and starting page are overloaded into the same method(s).

matthewp avatar Jan 19 '18 12:01 matthewp