Navigating through URLs in Angular.js using html5Mode enabled

I am trying to implement accessible and bookmarkable URLs that are routed by angular.js.

This application can be accessed through a specific part of the website at http://example.com/application/

Anything that comes after /application/ is considered a route param.

My goal is to have a URL that can be accessed either by

http://example.com/application/#/filter1/filter2/filter3/
                               ^ hashbang here

or

http://example.com/application/filter1/filter2/filter3/
                              ^ no hashbang here

I would expect angular.js to pass these route params to my application, but instead it defaults to .otherwise.

Setting Up Basic Routes

$locationProvider.html5Mode(true); // this requires base-tag to be set in dom, 
                                   // but isn't working for me

$routeProvider
    .when('/application/:filter1/:filter2/:filter3', {
        action: 'filter',
        reloadOnSearch: false
    })
    .otherwise({
        redirectTo: '/application/' + filter1 + '/' + filter2 + '/' + filter3
    });

In the HTML of the application, I added

<base href="/application/" />
, which seems to work initially. However, reloading the page or revisiting it after going through the .otherwise-route results in a "Page not found" error from the server.

If I disable HTML5 mode and remove the base-tag, it still doesn't function properly and I end up being routed through .otherwise.

Answer №1

The issue arises because your server recognizes application/ (and possibly returns application.html), but it does not recognize

application/filter1/filter2/filter3/
due to the absence of filter3.html.

Here are some solutions:

  • Opt to utilize only the hash syntax (the server reads everything before the # and allows the browser, like Angular in your case, to handle everything after).
  • Configure your server so that any path starting with application/* redirects to application.html in the browser.

Additionally, consider removing the base from the route provider:

$routeProvider
.when('/:filter1/:filter2/:filter3', {
    action: 'filter',
    reloadOnSearch: false
})
.otherwise({
    redirectTo: '/' + filter1 + '/' + filter2 + '/' + filter3
});

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

How can I convert Double Quotes from (") to (&quot;) in TinyMce Editor?

While using TinyMce Editor, I have encountered a problem with double quotes breaking my code. In the HTML source of TinyMce, it displays " instead of &quot, causing issues in conversion. It seems that it is not converting " to " as it should, simi ...

Issue with Material-UI tab when using a datatable within it's content

I implemented the Simple Tabs feature from Material-UI with a Tab containing a Datatable using React-Data_Table. However, I noticed that this particular tab is not responsive like the others when the table is full. Empty Full Here's a snippet of th ...

Can you explain the meaning of `<%= something %>` to me?

I've been working on a javascript project and I'm curious about the purpose of surrounding a variable with this syntax? <%= variable %> I attempted to research it myself but didn't come across any helpful information, so my apologies ...

The v-on:click event handler is not functioning as expected in Vue.js

I am currently learning vue.js and facing some challenges. Below is the code snippet from my HTML page: <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="https://cdn.jsdelivr.net ...

An issue with Azure App Service causing extra slashes in URLs

I am currently developing a node.js application that is being deployed on Azure App Service. On my local machine, the application functions perfectly at: http://localhost:55231/search?q=pink+floyd However, when deployed on Azure, the URL behaves strange ...

Angular-Node application experiencing issues with the persistence of sessions across CORS calls

Trying to set up a basic express session and save it in mongodb has hit a roadblock as the session does not persist during CORS calls. The setup involves using express-sessions and saving the session in 'mongodb' through 'connect-mongodb-se ...

Manipulating nested arrays in AngularJS by using the Splice method

Hey there, I need some assistance with removing an element from a nested JSON array like the example below: JSON [{ "id": 1, "name": "Furniture & Fixture", "choice": { "0": { "req_goods": "table", "qty": "1 ...

What is the best way to display multiple modals in a React app?

I am facing a challenge where I need to render multiple modals based on the number of items in the 'audios' property of an object. Currently, I am using the mui modal library for this functionality. Here are the variables being utilized: const ...

Creating a visually dynamic stack of images using javascript, jquery, and HTML

I'm interested in creating a unique image viewer using javascript/jQuery/HTML that combines elements of a book page flip and iTunes coverflow, optimized for mobile device browsers. I've been searching for tutorials to help kickstart this project, ...

Show information from a form within a react webpage

I'm currently working on a to-do app and my directory structure includes the following main files: App (renders the main page with header and buttons) export default class App extends React.Component { constructor(props) { super(props); thi ...

Encountering an Unexpected Token Error While Parsing JSON with jQuery

Utilizing the Envato API with jQuery to collect user stats is my current project. An example JSON response that I will display is as follows: { "new-files-from-user":[ { "thumbnail":"http://3.s3.envato.com/files/60560.jpg", "tags":"", "use ...

Utilizing React Typescript to Efficiently Manage Multiple Checkboxes within a List

I'm working on a scenario where I have to manage multiple checkboxes in a list Only one checkbox can be selected at a time For example, if I toggle on Checkbox 1 and then click on Checkbox 2 - I want to automatically toggle off Checkbox 1 as I toggl ...

Create a stylesheet document.write function that will never be true

While examining the source code of a webpage, I stumbled upon this intriguing piece of JavaScript right after the standard stylesheet declaration: <script type="text/javascript"> if('' != '') { document.write("< ...

The magic of Angular's data binding post-ajax retrieval

My situation is as follows: /items/item/123/edit and I have a controller that combines both the view and edit functionalities: ... if ($routeParams.id) { $scope.itemId = $routeParams.id; $scope.editMode = true; Item.getB ...

Enhancing VueJS2 components by optimizing code structure to eliminate duplicate elements

The following code is used in two different components, so please avoid using props. Utilize data variables and largely similar methods but with different component templates. <template> </template> <script> export default { name ...

The absence of "_ssgManifest.js" and "_buildManifest.js" files in a Next.js application deployed on Google Cloud Platform was discovered

Upon opening the website, there are instances where the console displays the following errors: GET https://example.com/subpath/_next/static/9ufj5kFJf/_buildManifest.js [HTTP/3 404 Not Found 311ms] GET https://example.com/subpath/_next/static/9ufj5kFJf/_ss ...

What is the process for renaming folders with files in node.js?

The current method is effective for renaming a single folder with no files, but it fails when trying to rename a folder containing one or more files. const handleRenameFile = () => { const oldPath = `./${directory}/${fileName}`; const newPath = ...

Extract the value from JSON data

I am faced with the challenge of extracting the value of slug from each child in a JSON dataset. The issue lies in the fact that I cannot predict how many children will be generated whenever new data is received. The generation of nested children is dynam ...

Show the screen name of a user upon disconnecting from the server

When a user disconnects from the server, I want to display a message. Currently, the message is shown to all users, but I'm having trouble displaying the actual user's name. Instead, it shows the name of the connected clients to themselves. I&apo ...

Exploring scroll functionality with Webdriver.io v4

My code is designed to log into the beta version of mediawiki, navigate to the Preferences page, and attempt to click on a button located at the bottom of the page. In order to achieve this, I am utilizing the scroll() function because using only .click() ...