Search code examples
page.js

How to examine url and emit routing with page.js


Is it possible to emit routing on the current URL, i.e., get page.js to call the respective callback on the current path?

The use case for this is if a user is signing in/out of my app, I want page.js to then route on the current path, since the current route may show different views based on authentication status.

I was using the Riot.js router and just switched over to leverage some page.js features, but page.js seems to be missing this core feature that Riot.js has (see here).

p.s. Currently my workaround is simply location.reload(), but this is not ideal.


Solution

  • You can cause Page to route to any arbitrary URL by simply calling page with the URL.

    So in your case, you might try:

    page( location.pathname );
    

    Or if you have some other method of maintaining a method of what route you're currently on:

    page( someStorageMechanism.currentRoute );
    

    However, location.reload(); is unlikely to ever break. I would personally consider this ideal, rather than less than ideal. Why not use the native browser behaviors?