The route you are trying to access is currently unavailable

I've successfully developed a web app, and now I need to replicate the same HTML page with a slightly different controller. Despite my attempts to utilize ngRoute, it's not functioning as expected, and I'm uncertain if my route setup will yield the desired outcome.

Upon running my code, I encounter the following error: Failed to instantiate module ngRoute due to: Error: [$injector:nomod] Module 'ngRoute' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

Edit: I've included Angular-route.js in my index file, but I'm now receiving the error "Unknown provider: $routeProvider"

Can someone shed light on why my routes aren't functioning correctly?

Here is the snippet of my code:

App.js (Routing Section)

app = angular.module('rcr_sched', ['ngRoute']);

app.config(['$routeProvider',
       function($routeProvider){
       When('/',{
           templateUrl: 'index.html',
           controller: 'main'
       }).
       When('/drill',{
           templateUrl: 'drill.html',
           controller: 'drill'
       }).
       otherwise({
        redirectTo: '/'
        });  

}
]);

Index.html

<html>
      <head>
        <link rel="stylesheet" type="text/css" media="all" href="app.css" />
          <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
        <link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet">
        <script type="text/javascript" scr="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-route.js"></script>
        <script src="js/angular.js"></script>
<script src="js/angular-route.js"></script>
        <script src="js/domo.js"></script>
        <script src="js/app.js"></script>      
      </head>
      <body ng-app="rcr_sched" ng-controller="main">
          <div id="mydiv" ng-view>
            <table>
                <tr>
                    <th id="printc"><button id="print" class="fa fa-print fa-2x" onclick="print('#mydiv')"></button></th>
                    <th ng-repeat="prop in columns">{{prop.date}}</th>
                </tr>  
                <tr ng-repeat="r in data">
                    <td id="linkc">
                    <button id="link" class="fa fa-plus-square fa-1x" onclick="href='#/drill'"></button>
                    </td>  
                    <td align="center" ng-repeat="prop2 in columns" class="{{getColor(r.TeamRank, r.Team, prop2.title)}}" style="{{isPTO(prop2.title, 'PTO' + prop2.title, r['PTO' + prop2.title])}}">
                        {{r[prop2.title]}}
                    </td>
                </tr>
            </table>
          </div>      
      </body>
    </html>

Drill.html

<html>
  <head>
    <link rel="stylesheet" type="text/css" media="all" href="app.css" />
      <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
    <link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet">
      <script src="https://ajax.googleapis.com/ajax/libs/angular-ui-router/1.0.0-rc.1/angular-ui-router.min.js"></script>
    <script src="js/angular.js"></script>
    <script src="js/domo.js"></script>
    <script src="js/app.js"></script>      
  </head>
  <body ng-app="rcr_sched" ng-controller="main">
      <div id="mydiv">
        <table>
            <tr>
                <th><button id="print" class="fa fa-print fa-2x" onclick="print('#mydiv')"></button></th>
                <th ng-repeat="prop in columns">{{prop.date}}</th>
            </tr>  
            <tr ng-repeat="r in data">
                <td>
                <button id="link" class="fa fa-plus-square fa-1x" onclick="href='#/'"></button>
                </td>  
                <td align="center" ng-repeat="prop2 in columns" class="{{getColor(r.TeamRank, r.Team, prop2.title)}}" style="{{isPTO(prop2.title, 'PTO' + prop2.title, r['PTO' + prop2.title])}}">
                    {{r[prop2.title]}}
                </td>
            </tr>

        </table>
      </div>      
  </body>
</html>

Answer №1

It is important to make the following changes in your code:

  1. Ensure that you only import files into a single root HTML file, typically named index.html.

  2. The angular.js file should be imported before any other file, such as angular-route.js.

  3. There should be only one ng-app tag; remove any extras from the drill.html file.

  4. It is unnecessary to provide an ng-controller attribute in the HTML since it is already defined in the route configuration.

  5. Separate the routing logic of your index.html file; extract the necessary parts of the default route (/) into another file, like home.html.

  6. Move the <table>.../<table> section to separate routing HTML files (home.html, drill.html), which will be managed by the ng-view directive.

For reference, you can view this example on Plunker.

Essentially, ensure that your app's routing logic is contained within ng-view. As a general template:

 <body>
    <header>
        <h1>App title</h1>
        <ul>
          <li><a href="#/">Home</a></li>
          <li><a href="#/drill">drill</a></li>
        </ul>
    </header>
    <div class="content">
        <div ng-view></div>
    </div>
</body>

Answer №2

The router is located in its own angular file and must be included in your index.html as follows:

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

Formik's handleChange function is causing an error stating "TypeError: null is not an object (evaluating '_a.type')" specifically when used in conjunction with the onChange event in DateInput

When using the handleChange function from Formik with the DateInput component in "semantic-ui-calendar-react", I encountered an error upon selecting a date. https://i.stack.imgur.com/l56hP.jpg shows the console output related to the error. AddWishlistFor ...

Challenges with Webpack sourcemaps

As I delve into learning nodejs and react, my current challenge lies in building bundle.js and debugging it within the browser. However, despite creating the bundle.map file, I am faced with errors as the webpack tab fails to appear in the browser. DevTool ...

Reversing the sequence of code in JavaScript - react native

I'm currently working on tracking the number of times a button is pressed within one second. For the most part, it's functioning correctly as it tracks and displays the count. The issue arises when it displays the button press count from the pr ...

Material UI - Exploring the Tree View Component

Seeking advice on structuring server data for utilization with the TreeView component from Material UI: https://material-ui.com/api/tree-view/ I need to efficiently handle large datasets by fetching child nodes dynamically from the server upon user intera ...

Adding a sign at the center of a map in React-Leaflet

One of the features I added to the map is a center indicator sign. <MapContainer fullscreenControl={true} center={center} zoom={18} maxNativeZoom = {22} maxZoom={22} classNa ...

Where can I locate the Socket.IO server within the local area network (LAN)?

I am currently in the process of developing an application that facilitates connections between devices within the same network. In my design, any device can act as a server, and I aim for clients to automatically detect the server without requiring users ...

Discovering the true width of an element using JavaScript

Hey there, I'm currently attempting to determine the exact width of a specific element and display an alert that shows this width. The code I am using is as follows: HTML Element <table cellspacing="1" cellpadding="5" style=";width:975px;border: ...

The string obtained from input.getAttribute('value') is lacking one character

While developing e2e-tests for an angular application, I encountered a puzzling issue. When trying to retrieve the value from an using the .getAttribute('value') method, I noticed that a single character was missing. Checking the HTML properties ...

Start the input field with the prefix "APP" and restrict the input to only numbers

My challenge involves creating an input field that requires a prefix of "APP " followed by 7 numeric digits. I initially considered using ngx-mask, but it appears to be impossible. Another approach I thought of was utilizing the (focusin) event like this: ...

Ways to adjust the size or customize the appearance of a particular text in an option

I needed to adjust the font size of specific text within an option tag in my code snippet below. <select> <?php foreach($dataholder as $key=>$value): ?> <option value='<?php echo $value; ?>' ><?php echo ...

Position divs to be perfectly aligned and centered

I'm in the process of creating a webpage and facing challenges with aligning my divs properly, specifically the animated company logos. I want them to be positioned side by side rather than on top of each other, with space in between to fit the layou ...

The .env file is functioning properly for the current keys, but any new ones I include remain undefined

Recently, I took over a Vue application that utilizes axios. Within the dataService.js file, it retrieves URLs from a project's .env file using process.env.FOO_BAR for GET requests. The pre-existing key-value pairs such as VUE_APP_DATA_URL function p ...

The issue with data targeting in Bootstrap 3 persists

header.php code <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN"> <html lang="EN"> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta http-equiv="Content-Type" content="text/html; charset=UT ...

Using the Nodejs Array prototype filter method within a JSON object

Attempting to create a function that filters and returns specific strings within JSON data. Any advice is appreciated. Thank you! [ { line: '{"status":"waiting"}' } ] var body_W = []; body_W.push({line: JSON.stringif ...

Creating an animated full-width SVG with a background image

This has been quite a challenge for me. I have successfully implemented the main functionality that I wanted in this codepen. The SVG is divided into 3 sections, with the middle section sliding away from the others when you click the "Find Out More" button ...

What role does the "deep" parameter serve when declaring a watcher in VueJS?

I recently discovered a feature in Vue.js called watchers while working on my web app. As I was exploring the API documentation, I came across a flag known as deep. This flag caught my attention because it defaults to false. I'm curious to know what s ...

What is the best way to add data to my collection using the main.js file on the server side in a Meteor application

I am a beginner with Meteor and trying to customize the tutorial codes. I have a code that listens for packets on my server-side main.js. Now, I need to store the data printed on the console into my database collection. import { Meteor } from 'meteor/ ...

Guide on how to conditionally display a button or link in a Next.js Component using TypeScript

Encountering a frustrating issue with multiple typescript errors while attempting to conditionally render the Next.js Link component or a button element. If the href prop is passed, the intention is to render the Next.js built-in Link component; otherwise, ...

Having trouble setting the InnerHTML property of Null on my Ionic app, what could be the issue?

I'm working on a code to display the remaining time for generating a random code in the DOM. var count = setInterval(function () { var date = new Date(); var currentSecond = date.getSeconds(); ...

I am struggling to render the pages and components in React while using BrowserRouter

Below is the code snippet for App.js and Home.js that I'm working on. My aim is to showcase the Home.js component in the browser. App.js import "./App.css"; import { Route, BrowserRouter } from "react-router-dom"; import Home from ...