What's the reason why Angular stops flickering with the use of "/" in href?

Recently, I've come across a peculiar issue in one of my web applications while using Angular's routeProvider as a template engine. The app functions properly, but the behavior seems inexplicable to me.

The problem arises during page transitions (particularly in Safari and mobile Safari) where the next page momentarily flickers at the front before transitioning smoothly. Surprisingly, adding a slash ("/") at the end of the href URL like href="#/home/" instead of href="#/home" resolves this issue. Can anyone shed light on why such a simple change fixes this unexpected behavior?

This is how I configured the routeProvider:

.config(function($routeProvider) {
    $routeProvider.when('/home', {
      controller: 'HomeCtrl',
      templateUrl: './home.html'
    }).when('/pageTwo', {
      controller: 'twoCtrl',
      templateUrl: './pageTwo.html'
    }).otherwise({
      redirectTo: '/home'
    });
  })

My HTML structure looks like this:

<ul id="nav">
    <li>
        <a href="#/home" class="bt-icon">HOME</a>
    </li>
    <li>
        <a href="#/pageTwo" class="bt-icon">TWO</a>
    </li>
</ul>

And here is the CSS styling I used:

.view-animate-container {
    position: relative;
    width: 100%;
    height: 100%;
}
.view-animate {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-perspective: 1000;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
}

.view-animate.ng-enter,
.view-animate.ng-leave {
    -webkit-transition: all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
    -moz-transition: all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
    -o-transition: all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
    transition: all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
}

.view-animate.ng-enter {
    opacity: 0;
    -webkit-transform: translate3d(20%,0,0);
    transform: translate3d(20%, 0, 0);
}
.view-animate.ng-enter.ng-enter-active {
    display: block;
    -webkit-transform: translate3d(0,0,0);
    transform: translate3d(0, 0, 0);
    opacity: 1;
}
.view-animate.ng-leave.ng-leave-active {
    -webkit-transform: translate3d(-20%,0,0);
    transform: translate3d(-20%, 0, 0);
    opacity: 0;
}

Answer №1

Is there a specific rationale behind linking to the hash rather than the actual route?

Have you experimented with updating your links to

<a href="/home">Home</a>
instead of href="#/home"?

Angular is capable of handling the hash for you, especially if pushState is supported by your browser.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Warning: When VueJs OnMount props is utilized, it might display a message stating, "Expected Object, received Undefined."

This is my current component setup: <template> <Grid :items="items" /> </template> <script setup> import { ref, onMounted } from 'vue' import Grid from '@/components/Grid.vue' import { getData ...

The logic behind combining elements from two arrays in JavaScript/TypeScript

Explanation of two different array formats const arr1 = [ { "elementName": "one" }, { "elementName": "two" } ] const arr2 = [ { "type": "RPT_PROPERTY_DEMOGRP", "values": [ { "label": "HH" }, { " ...

The Controller of Conversations

In the HTML code, there is a dialog element with an identification of divMyDialog1. This dialog is connected to a JavaScript class called MyDialog1. Each dialog has its own unique id and associated class name. MyDialog1 = function(divStr){ this.divStr ...

What is the best way to implement a function that can be passed as a parameter to the express.get

The app variable is defined by const app = express(); The above code snippet is functioning properly: app.get('/posts/:id', (req, res) => { res.json( post_creator.CreatePost(req.params.id) ); }); However, the code below is not function ...

Showing live JSON data in AngularJS

Receiving a JSON string from a web service, the content may differ depending on the request. Here are 2 JSON results: Result 1 [ { "Key": 1, "ID": 1, "applicationId": "1", "applicationName": "APP1" }, { "Key": 2, "ID": 1, ...

The React application functions smoothly when executed using react-scripts start, but encounters an "Unexpected SyntaxError: Unexpected Token: <" error upon building

My goal is to deploy my portfolio site using an express server and react-scripts build. Everything works perfectly fine when I run react-scripts start. However, when I try to serve up the build index.js, I encounter the following errors: 2.8b4a0c83.chunk.j ...

What is the reason behind using AJAX to attempt sending a new URL request on

Having a strange issue with my product list. When trying to edit a product by clicking on it, I am redirected to the product form where an AJAX request is supposed to be sent to getFiltersGroup. However, on error, the AJAX request is somehow being sent to ...

Modify JSON date format to a shorter version using the first 2 letters of the month and the year

Looking to convert date values in a JSON array from "December 2016" format to "D16". Hoping to accomplish this using Regex, any assistance would be greatly appreciated. [["November 2016","December 2016","January 2017","February 2017","March 2017"],["tot ...

Create a border that does not inherit the opacity of the object

Check out this jsBin for reference: http://jsbin.com/uyonux/1 The hover state is working fine, but the focus state is not. I want the blue color to remain solid #13A3F7 without inheriting the opacity of .4. Is there a way to achieve this without the elem ...

Transferring information from one page to the next

How can I efficiently transfer a large amount of user-filled data, including images, between pages in Next.js? I've searched through the Next.js documentation, but haven't found a solution yet. ...

Locate an array within a Multidimensional array and relocate it to the starting position

I've been attempting to figure out a solution for moving a specific array within another array to the beginning. The problem I'm encountering is that the code I was using, as suggested in a previous question, only removes the last value and plac ...

Tips for integrating Grails ${createLink} into your javascript code

Below is a JavaScript function that I have: function GetSelectedItem() { var e = document.getElementById("country"); var strSel = e.options[e.selectedIndex].value; alert(strSel); var url = "${createLink(controller:'country', act ...

Angular is throwing an error during generation

After manually installing nodejs and npm on my ubuntu 14.04, I checked the versions: root@wemet:~/ang# npm version { http_parser: '1.0', node: '0.10.34', v8: '3.14.5.9', ares: '1.9.0-DEV', uv: '0.10.30', z ...

What is the reason for the maximum alias number in the npm YAML library?

I have been utilizing the npm module yaml to convert complex, interdependent JavaScript objects into a text format that can be easily restored in Javascript. Additionally, I use this package for deep copying of deeply nested objects by serializing and then ...

Observable Knockout Dependency

I found an interesting example on the KnockoutJS site () and I want to implement something similar. My goal is to check if certain values are available on the client side when a category is selected. If they are not, then I need to fetch them from the ser ...

Importing local JSON files into Vuex state

I am looking to import data from a local JSON file into a state value setting within my Vue.js application. store/index.js import { createStore} from 'vuex' export default createStore({ state: { settings: {} } }) assets/json/settings.j ...

The export "hasInjectionContext" is not provided by the source file "node_modules/vue-demi/lib/index.mjs", but it is being requested in the file "node_modules/pinia/dist/pinia.mjs"

Every time I launch my program, the console displays an error message stating that "hasInjectionContext" is not exported by "node_modules/vue-demi/lib/index.mjs", imported by "node_modules/pinia/dist/pinia.mjs" at line 6:9. I ...

Troubleshooting 404 errors with Cordova, AngularJS, and Node.js (Express) when using $http with

I'm currently testing in an Android environment using Cordova, AngularJS, and Node.js (Express). I'm attempting to retrieve some data using $http(), but consistently encountering a 404 error message (as seen in the alert below). Here's the ...

Exploring a collection of objects housed in a json document

Currently, I'm looking to retrieve a collection of objects using JavaScript from a JSON file that resides on my website. While I could easily embed the array of objects directly into my JavaScript code, I am interested in understanding how to work wit ...

Design Pattern of AngularJS/Bootstrap Application

Seeking guidance on structuring a small AngularJS application for a simple stock charts app. As a seasoned developer but new to AngularJS, I am looking for the best approach. App Overview The app includes a left-hand "nav" bar for adding and selecting s ...