Coder Social home page Coder Social logo

Comments (7)

Anthodpnt avatar Anthodpnt commented on May 7, 2024

Hi @TristanPct,

If you had the data-router-disabled attribute to your link Highway won't attach any click listener to it meaning you can do the event.preventDefault() like you would do usually because the link is not attache to Highway.

Can you please try and come back to us ?

Thanks,
Anthodpnt

from highway.

TristanPct avatar TristanPct commented on May 7, 2024

Yes, it's what I do for the moment.

My use case is:

  • By default use Highway router on links
  • If users windows width is small prevent links click

So I tried something like:

function onLinkClick(event) {
    if (window.innerWidth < 1150) { // Small screen no redirect
        event.preventDefault(); // Ignored by Highway
       //...
    } else { // Normal case
       //...  
    }
}

For the moment I have to add data-router-disabled on my links and:

function onLinkClick(event) {
    if (window.innerWidth < 1150) { // Small screen no redirect
        event.preventDefault(); // Prevent browser redirection
        //...
    } else { // Normal case
        highwayCore.redirect(event.target.attributes["href"].value);
        //...
    }
}

from highway.

Anthodpnt avatar Anthodpnt commented on May 7, 2024

If I understand you want to disable the transition on small screens ?
Why don't you just call Highway.Core when the screen is over 1150 ?
Why would you remove the click on a link on mobile but not on desktop ?

from highway.

TristanPct avatar TristanPct commented on May 7, 2024

I want to disable my links (not only the transition) on mobile for a menu like this:

  • Parent 1
    • Child 1.1 (Parent 1 alias)
    • Child 1.2
  • Parent 2
    • Child 2.1 (Parent 2 alias)
    • Child 2.1

On desktop all links are visible, on mobile I have a burger menu, Child 2.1 is visible only if I click on Parent 2, but if I'm redirected to Parent 2's page I can't see the Child.
So on mobile I have to prevent default redirection behavior on click, just for parents links.

With my second script, it works like I want.

It's more a suggestion than a bug to add something allowing to programmatically disable the router on a link click.

from highway.

Anthodpnt avatar Anthodpnt commented on May 7, 2024

My suggestion would be to create both a a and a button in your DOM and play with CSS to display one or the other based on the window size instead of hacking the Javascript to disable the event on mobile because you have a burger menu.

But the question to disable the router on selected links has been asked and we'll take a look to add this feature as soon as possible.

Best regards,
Anthodpnt

from highway.

wezzou1 avatar wezzou1 commented on May 7, 2024

I'm using two menus (one for mobile) and (on for desktop) and it's working perfect to display data-router-disabled on Parent's to make a nice dropdown :)

from highway.

Anthodpnt avatar Anthodpnt commented on May 7, 2024

I suppose this issue can be closed for now :)

from highway.

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.