Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Josh Evenson 10 posts 113 karma points
    May 02, 2017 @ 18:47
    Josh Evenson
    0

    Umbraco 7.5 Adding / to URL after Anchor #

    We're having a strange issue with links to our site with anchor tags.

    www.site.com/page-name#anchor-id
    

    Gets changed to

    www.site.com/page-name#/anchor-id
    

    causing the anchor not to work.

    Any ideas on what would cause this?

    <addTrailingSlash>false</addTrailingSlash> is already off

  • Josh Evenson 10 posts 113 karma points
    May 02, 2017 @ 19:13
    Josh Evenson
    101

    Discovered that this is due to AngularJS that is in the web app.

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    May 02, 2017 @ 20:17
    Nicholas Westby
    1

    Yeah, ran into that myself. There is an AngularJS config value that disables that behavior.

    angular.module("yourApp").config(function ($locationProvider) {
        $locationProvider.html5Mode({
            enabled: true,
            rewriteLinks: fase,
            requireBase: false
        });
    });
    

    Not sure if all of those values are necessary, but that's what I set it to on one of my sites. More info here: https://docs.angularjs.org/api/ng/provider/$locationProvider

  • Josh Evenson 10 posts 113 karma points
    May 02, 2017 @ 20:18
    Josh Evenson
    0

    Yeah, I've tried that config for html5Mode and it wasn't helping. Thanks for the reply though.

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    May 02, 2017 @ 21:01
    Nicholas Westby
    1

    Have you tried it with those exact three parameters? IIRC, it didn't work for me when I tried it with just rewriteLinks set to false.

  • Josh Evenson 10 posts 113 karma points
    May 02, 2017 @ 22:37
    Josh Evenson
    1

    You hit the nail on the head! I was so close earlier, I just didn't include the requireBase property. Thanks for the help, Nicholas!

  • Josh Evenson 10 posts 113 karma points
    May 03, 2017 @ 15:14
    Josh Evenson
    0

    Okay, now AngularJS is intercepting all anchor tags on the page, and none of the links work unless you add target="_self", which isn't an option...

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    May 03, 2017 @ 15:44
    Nicholas Westby
    0

    Is that still the case when you set enabled to true (or to false)?

    What happens when you click an anchor tag? Does the URL change? To the correct value? Does it scroll down the page (assuming that's what you want)?

  • Josh Evenson 10 posts 113 karma points
    May 03, 2017 @ 16:10
    Josh Evenson
    0

    Yeah with enabled: true, clicking on an a tag will update the url as expected but the navigation will not occur.

  • Josh Evenson 10 posts 113 karma points
    May 03, 2017 @ 16:23
    Josh Evenson
    1

    I had to remove $location from one of my controllers. That did it.

Please Sign in or register to post replies

Write your reply to:

Draft