AngularJS - encountering a 404 error when reloading the page after removing the Hashbang

After taking out the hashbang from my routes by using

$locationProvider.html5Mode(true);

Now, when I go to a page like "domain.com/download", it works. But if I refresh this same page, I get a 404 Error. URLs like "domain.com/download" can only be accessed by entering "domain.com/#!/download". After it loads, it automatically redirects me to the regular "domain.com/download" page.

I'm using v1.3.2 for routing and v1.6.3 for the rest (don't ask me why I didn't build this site myself lol).

Answer №1

The information provided in the AngularJS Documentation highlights the necessity for URL rewriting on the server side. Essentially, all links must be redirected to the main entry point of the application, such as index.html. It is crucial to include a base tag to allow AngularJS to differentiate between the application base and the specific path that needs to be processed by the application.

Adapting your .htaccess file is vital, and it may look similar to the following:

RewriteEngine On 
Options FollowSymLinks

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /#/$1 [L]

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

What is the best way to retrieve an object from every function?

I'm dealing with a <div> containing radio buttons: <div id='RB-01'> <span>Item_1</span><input type='radio' name='RB01' value='1'><br /> <span>Item_2</span><inp ...

Combining Asynchronous and Synchronous Operations in a Function: Using Cache and Ajax Requests in JavaScript

I am currently exploring how to combine two different types of returns (async / sync) from a function that is structured like this : retrieveVideo(itemID){ let data = localStorage.getItem(itemID) if ( data ) { return data; } else{ axios.ge ...

Delete local data storage in Angular 2 upon closing the window

After the user logs in, I store their token in local storage so that it is accessible across all tabs. However, I need to remove this token from local storage when the user closes the browser or window. What is the best way to clear local storage upon clo ...

SignalR does not include cookies in the connection request

While working on a web application using ASP.NET Web API and SignalR, I encountered an issue that is proving to be quite challenging despite my understanding of HTTP. Currently, I have successfully set a cookie on all AJAX requests to the API, and subsequ ...

Swapping out video files with varying quality using HTML5 and Jquery

Objective: Implementing a feature to change the video being played when a user clicks a button using Jquery. Example website for reference: (click on the "hd" button in the player control) More details: When the page loads, the browser will play the fi ...

Tips for clearing the browser cache when working with AngularJS in HTML code

Does anyone know how to clear the browser cache in HTML when using AngularJS? I've tried adding the following code to my index.html file and also used $templateCache in my app.js without success. <meta http-equiv="Cache-Control" content="no-cache, ...

Discover if every single image contains a specific class

HTML : <div class="regform"><input id="username" type="text" name="username" placeholder="Username" required><h3 class="check"><img src=''/></h3></div> <div class="regform"><input id="password" type=" ...

Reversing data in Vue3

I've been struggling to create a custom dropdown for my application. I need to implement a function that adds a class called is-active to a div element. So, what I have done is created a simple div with an onclick function as shown below: <div :cla ...

Sorting of array in AngularJS ngRepeat may result in changing the length of the array

Link to JSFiddle: http://jsfiddle.net/WdVDh/101/. When updating the sorting option for an ng-repeat list, I noticed that the array length changes and in my local version, all items disappear. My code involves filtering and sorting, with the ability to fi ...

Combining and adding arrays that share the same key

Currently, I am working with a for loop that extracts data for each user from the matchlistResponsestats object. Once the for loop completes its iterations, I end up with approximately 90 arrays in this format: ["username", kills, assists, deaths] My goal ...

Tips for utilizing window.scrollTo in tandem with react/material UI?

I have a simple functional component that displays an alert panel with an error message under certain conditions. The issue I am facing is that when the alert panel is rendered due to an error, it might be off-screen if the user has scrolled down. To addre ...

Preventing html entities in emails sent using Laravel and Summernote: A guide

I'm encountering a problem with Laravel 5.1 and summernote. I am utilizing summernote to compose an email, which is then sent via angular.js to a laravel 5.1 API. Despite my efforts to troubleshoot, I can't seem to send the email in HTML format ...

Exploring the ins and outs of HTML event handlers with JavaScript

When using events in your HTML and including a small amount of JavaScript, what is this called? Is it referred to as a "JavaScript attribute function," simply a "JavaScript attribute," or something else entirely? For example: <button onClick="locat ...

Why isn't Meteor.call functioning in the stub?

As I delve into the realm of async JavaScript coding, I have encountered a gist that has left me puzzled: https://gist.github.com/dariocravero/3922137 Specifically within client_save.file.js - there are parts of this code snippet that baffle me: fileRead ...

Is it feasible to dynamically incorporate various versions of Bootstrap within the head tag?

The CMS I'm currently working with has a strict dependency on a specific version of Bootstrap. However, there are features from Bootstrap 3.3.6 that I need based on the page being loaded in the browser. I initially considered using JavaScript or jQue ...

Tips for deleting default text from MUI Autocomplete and TextField on click

I am currently using Material-UI (MUI) Autocomplete feature with a TextField element, and I have a specific behavior that I would like to achieve. Currently, when I click on the search bar, the placeholder text moves to the top of the TextField. However, m ...

Transmit the Selected Options from the Checkbox Categories

Here's an intriguing situation for you. I've got a webpage that dynamically generates groups of checkboxes, and their names are unknown until they're created. These groups could be named anything from "type" to "profile", and there's a ...

Parent Directory Injector: Prioritizing Injection of Parent Directories

Currently, I am utilizing 'grunt-injector' to inject a list of files using 'app/**/*.js'. However, I am facing dependency errors due to the alphabetical order in which the files are injected. To avoid these issues, I am looking for a so ...

Error: The EJS compiler encountered a SyntaxError due to an unexpected token || in the show component file located at /var/www/html

I'm currently working on a project inspired by Colt Steele's YelpCamp creation during his Udemy Web Dev Bootcamp. Everything was going smoothly until I tried to refactor some code towards the end of the course using YouTube tutorials. Now, whenev ...

Trouble with Add To Cart feature in React app due to issues with Context API

I have been following a tutorial located here. I followed the steps exactly and even checked the code on the related github repository, which matches. However, when I try to add a product to the cart by clicking the button, the state does not update. In Re ...