Giter VIP home page Giter VIP logo

Comments (9)

KidkArolis avatar KidkArolis commented on July 24, 2024 1

You want to use both pushState and hashes at the same time? As you've noticed - cherrytree in pushState mode will replace #/foo to /foo on startup. I will implement an option to disable this behaviour. This way, cherrytree will just use the URL as is and leave the hash alone. I might even look into exposing the hash as part of the router params.

The tricky bit here is that the automatic fallback to hash behaviour will kind of break. Tbh I don't know if browsers without pushState is still a thing. Perhaps, in this case, the router will go into hash mode and will simply drop the other hash. Would that be acceptable?

from cherrytree.

xrado avatar xrado commented on July 24, 2024

Actually this happens in location-bar lib on
https://github.com/KidkArolis/location-bar/blob/master/location-bar.js#L198
on start replaces /#something with /something

from cherrytree.

xrado avatar xrado commented on July 24, 2024

ok I solved it by settings location to BrowserLocation with custom options. Setting hashChange: false do the trick

const router = Cherrytree({
    interceptLinks: true,
    pushState:true,
    location: new Cherrytree.BrowserLocation({pushState: true, hashChange: false, root: '/'})
})

from cherrytree.

xrado avatar xrado commented on July 24, 2024

ahh.. that only works for initial router call, further transitions don't work anymore :/

from cherrytree.

xrado avatar xrado commented on July 24, 2024

I just want to use pushState (without legacy hash change) where urls may also include hashes.
An hash as part of router params and option to enable or disable fallback, yes that will be great.

from cherrytree.

xrado avatar xrado commented on July 24, 2024

With hashes included what would then happen when you'll navigate to same path and only the hash part will change? Transition won't fire, right? ..just hash part will change in url?

from cherrytree.

KidkArolis avatar KidkArolis commented on July 24, 2024

That's a good question, will have to try and find out. If I start passing hash as one of the params, then it might make sense to fire a transition (just like if a query param changes). If I don't pass hash as one of the router params to transition middleware, then perhaps I should ignore hash changes. Also - I'm not sure if I can even detect hash changes and push state changes at the same time in any sensible way.

from cherrytree.

xrado avatar xrado commented on July 24, 2024

I wouldn't fire transition if only the hash part changes, but url should be updated anyway. It looks like hash change won't fire a page jump (http://lea.verou.me/2011/05/change-url-hash-without-page-jump/) when changed via pushState, but thats ok I guess. If you are using pushState, you control what happens.

from cherrytree.

KidkArolis avatar KidkArolis commented on July 24, 2024

Hey, so this is still a very interesting issue for me, as making it possible to utilise hashes in cherrytree sounds like it could be a useful feature, e.g. for anchoring/scrolling to page elements like it's intended, or to encode some clientside params.

I don't have the time to look into how to implement this right away, but I'll keep this issue open for now.

from cherrytree.

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.