Error in refreshing the deployment package of angular 4 on an Apache server

At the moment, my Angular application runs on an Apache server at the 'http://localhost' root or index page. However, when I refresh the inner page 'http://localhost/dms-data/summary-of-findings', the browser displays

Page Not Found

The requested URL /dms-data/summary-of-findings was not found on this server.


Apache/2.4.9 (Win32) PHP/5.5.12 Server at localhost Port 80

this message in my browser my index.html base href is

<base href="http://localhost/">

Answer №1

The reason behind the 404 error you are experiencing is related to using HTML pushState as the location strategy in Angular. When you refresh the page from the browser, the request for your routed page is sent to the Apache server which is unaware of the internal routing by Angular.

To resolve this issue, there are two recommended solutions:

  1. Set index.html as the fallback page: Configure your server to redirect any unknown page requests (routed requests) to the main html file, index.html. This ensures proper handling of routed pages (Check this link for server configuration instructions)

  2. Use Hash based location strategy: By implementing this strategy, server configuration is not required. Routed page URLs will appear as localhost/#/route1. Keep in mind that this approach may impact SEO if you are creating a website (Refer to this link for further details)

Answer №2

To create a .htaccess file in your project directory, simply follow these steps:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

If you want to learn more about deploying an Angular build on an Apache server, you can visit this link: Deploy step

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

Angular Routing can be a powerful tool for managing multiple article posts in an efficient and organized way

I am in the process of building a website with Angular that features numerous articles. Whenever a user clicks on an article, I want it to navigate to a new URL using routing. To achieve this, I have created a new Article component and here is how my app- ...

Issue with Angular FormControl/FormBuilder not selecting options in Select dropdown

I am creating a form to edit some items and include a Select element with options loaded from a database. However, even though I set up the name and description correctly using formBuilder/control in the component, the correct "category" is not being selec ...

When converting an NgbDate to a moment for formatting needs, there is a problem with the first month being assigned as 0 instead of 1

I am encountering a challenge with my Ngb-Datepicker that allows for a range selection. To customize the output format, I am using moment.js to convert the NgbDate into a moment object (e.g., Wed Jan 23). One issue I encountered was that NgbDates assign J ...

The Angular service retrieves only the default values

I'm currently following an Angular tutorial and encountering some issues. Problem #1: The problem arises when using two services, recipe.service.ts (handles local data manipulation) and data-storage.service.ts (stores data in Firebase). When the getR ...

The absence of the google-services.json file has rendered the Google Services Plugin inoperable. Attempted search location:

Having an issue while trying to integrate my app with Firebase. The error message keeps indicating: > File google-services.json is missing. For a more detailed view of the error, please refer to the image below: https://i.stack.imgur.com/sgNYu.jpg D ...

The Angular application has encountered a stack overflow due to exceeding the maximum

./src/main.ts - An issue occurred: The module build process failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js): Error: Maximum call stack size exceeded import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; { App ...

Storing information from a signup form using Angular

Can you help with my registration form? <div class="form-group"> <label for="email" class="col-sm-3 control-label">Email Address</label> <div class="col-sm-9"> <input type="email" id="email" placeholder="Enter your ...

Solution for primeNG dataTable with colspan in the tbody area

Encountering a common issue where you need a col span for tbody instead of just headers provided in the PrimeNG Documentation. I attempted to add it programmatically using directives and JavaScript. Below is an example of the code. While this solution ma ...

Angular is unable to load additional routes

While working on building a web application with Angular 11, I encountered an issue with routing. When navigating from the initial route ( { path: '', component: HomeComponent } ) to other routes, everything functions as expected. However, when ...

How can I dynamically insert various FormGroup instances into a FormArray in Angular?

I am looking to dynamically populate the order array with multiple dishes. Each dish will be stored as a FormGroup in the form, such as pizza, salad, drink, or any other type of dish. Prior to adding any items, the form structure should resemble this: this ...

"Organizing Data with Angular 2's Sorting Pipe for Arrays of

Guide to Creating a Sorting Pipe in Angular 2 Using an Array of Objects Initial Challenge: I am working with a TODOs list (Todo[ ]), and I need to sort it every time modifications are made. The desired outcome is to have completed todos appear at the bot ...

Challenges encountered when setting a value to a custom directive via property binding

I'm working on a question.component.html template where I render different options for a specific question. The goal is to change the background color of an option to yellow if the user selects the correct answer, and to red if they choose incorrectly ...

Is it possible to verify if the @Output is correctly wired up within an Angular component?

When working with Angular and TypeScript, it is possible to access the bound @Input values in the ngOnInit method of a component. However, there isn't a straightforward way to check if a particular @Output event binding has been set up on the componen ...

I am able to view the node-express server response, but unfortunately I am unable to effectively utilize it within my Angular2 promise

https://i.stack.imgur.com/d3Kqu.jpghttps://i.stack.imgur.com/XMtPr.jpgAfter receiving the object from the server response, I can view it in the network tab of Google Chrome Dev Tools. module.exports = (req, res) => { var obj = { name: "Thabo", ...

A method for consolidating multiple enum declarations in a single TypeScript file and exporting them under a single statement to avoid direct exposure of individual enums

I am looking to consolidate multiple enums in a single file and export them under one export statement. Then, when I import this unified file in another file, I should be able to access any specific enum as needed. My current setup involves having 2 separ ...

Ways to enable components to access a string dependency token

I'm currently developing an Angular application that utilizes Angular Universal for server-side rendering functionality. One interesting aspect of my project involves passing a string dependency token as a provider within the providers array in serve ...

Guide to iterating through different endpoints in a predetermined sequence

I am facing a challenge with testing various endpoints using different login credentials. When looping through the endpoints, the results are not appearing in the sequential order due to asynchronous nature. My goal is to iterate through each endpoint wit ...

It appears that the input variables in Angular (5) are experiencing some issues

After upgrading my Angular project from version 4 to 5, I've noticed some unexpected changes in the behavior of my components. In my application, there is a ParentComponent and a ChildComponent. The ChildComponent receives an InputObject from its par ...

Angular | Creating a template reference variable for a division element

Utilize the code provided to create 4 divs each sized at 200x200. In order to apply a specific class to a div when the mouse is hovering over it (without affecting the other three), you need to follow these steps: <style> div {height: 200px; wid ...

Head to the "/unauthorised" route in Angular while maintaining the current URL intact

I have a security guard that directs the user to an "/unauthorised" route when they do not have permission to access the current page (which could be any page). @Injectable() export class PermissionGuard implements CanActivate { constructor(private reado ...