The Yeoman Angular Coffee router is not routing properly and displays an error message "cannot GET"

Struggling with getting the router to load a basic template after setting up a Yeoman angular scaffolder installation. Here's my configuration:

//  index.html
<body ng-app="mvmdApp">
  <div class="container" ng-view=""></div>//  not sure how ng-view plays into this


//  app.coffee
myAppModule = angular.module("mvmdApp", [])
  .config( ($routeProvider, $locationProvider) ->
    $locationProvider.html5Mode true

    $routeProvider
      .when("/",
        templateUrl: "views/main.html"
        controller: "MainCtrl"
      )
      .when("/youtube",
        templateUrl: "views/youtube.html"
        controller: "YoutubeCtrl"
      )
  )


//  main.js
angular.module('mvmdApp')
  .controller 'MainCtrl', ($scope) ->
    $scope.awesomeThingss = [
      'HTML5 Boilerplate'
      'AngularJS'
      'Karma'
    ]

    $scope.youtube = ( $scope ) ->
      alert 'hi'

  .controller "YoutubeCtrl", ( $scope ) ->
    alert 'Work!'


//  views/youtube.html
<div class="youtube-unit">
  <div class="outer-frame">
    <div class="inner-frame">
      <iframe width="560" height="315" src="//www.youtube.com/embed/2FNEiTjcMM0" frameborder="0" allowfullscreen="allowfullscreen"></iframe>
    </div>
  </div>
</div>

The main controller is loading successfully. I have tried duplicating it as much as possible.

When trying to access localhost:9000/youtube, I receive a Cannot GET /youtube message. I've experimented with various combinations but can't seem to get it working.

Answer №1

Although it may not be a simple process, you have the ability to set up the connect-modrewrite middleware by rewriting any path to index.html. Additionally, you will need to make adjustments to your GruntFile.js for live reload functionality and implement the rewrite on your production server as well. For guidance on how to tackle this task, check out these helpful tips -

Answer №2

HTML5 mode isn't just dependent on JavaScript; server support is also crucial.

When attempting to access /youtube, the request is first sent to the server. If the server cannot handle it, the Angular application should be rendered so that the router can process the route and display the necessary content.

I'm uncertain if Yeoman actually supports HTML5 mode.

You might want to consider using LinemanJS, as it is similar to Yeoman and does provide support for HTML5 mode.

If you prefer to stick with Yeoman, try searching for information on enabling HTML5 mode with Yeoman or use hashbang instead :)

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

Display a close button for every individual item and use JavaScript to conceal the current item

I have a list that contains input fields along with delete link elements. I want to display the delete link element when the user hovers over the respective input field. Additionally, clicking on the close button (X) should hide the entire list item (li) f ...

What is the reason for not being able to utilize interpolation expression with "ng-model" while being able to do so with "ng-src"?

My current challenge involves attempting to utilize the interpolation expression alongside the ng-model directive, but unfortunately I haven't been able to get it functioning. Interestingly, when I apply interpolation with the ng-src directive, everyt ...

Numerous comparisons between ngIf and ngShow are made when dealing with intricate user interfaces and form structures

After searching, I couldn't find a satisfactory answer to my question about when to use ngShow versus ngIf. Alternative to ng-show/-hide or how to load only relevant section of DOM What is the difference between ng-if and ng-show/ng-hide When to fav ...

What is the best way to make an array with values from a checkbox list?

I am working on a project that involves rendering a list of products categorized into different categories. Users can select these categories using checkboxes. Are you interested in learning how to create an array containing the selected values from the ch ...

Access SCSS variable values in Angular HTML or TypeScript files

So, I've been looking into whether it's feasible to utilize the SCSS variable value within HTML or TS in Angular. For instance: Let's say I have a variable called $mdBreakpoint: 992px; stored inside the _variable.scss file. In my HTML cod ...

Incorporate a CSS class name with a TypeScript property in Angular version 7

Struggling with something seemingly simple... All I need is for my span tag to take on a class called "store" from a variable in my .ts file: <span [ngClass]="{'flag-icon': true, 'my_property_in_TS': true}"></span> I&apos ...

Is it possible to activate the nearby dropdown based on the user's selection?

On my html webpage, I have a form that consists of three dropdown menus each with different options: The first dropdown (A) includes choices from 1 to 6, as well as 'not set'. The second dropdown (B) allows selections from 1 to 7, and also has ...

Display function not functioning properly following AJAX request

I'm working on a functionality where I want to initially hide a table when the page loads, and then display it with the results when a form is submitted using Ajax. The issue I'm facing is that the code refreshes the page and sets the table back ...

Leveraging a service variable in Angular

Is there a way to access data shared in a service within a directive? Let's say we have a directive called resultsDirective, and a service named dataService. How can we retrieve a variable from the service within the directive? angular.module("someMo ...

What is the best way to send multiple input box values to a function set in the controller?

I am attempting to send the values of two input boxes to a single controller function. <div class="container" ng-controller="MainCtrl"> <div class="row"> <div class="col-lg-6"> <input type="text" ...

How can I verify the status of an occasional undefined JSON value?

There are times when the JSON object I'm trying to access does not exist. Error: Undefined index: movies in C:\xampp\htdocs\example\game.php In game.php, I'm attempting to retrieve it from the Steam API using this code: $ ...

Exploring the depths of asynchronous calls in AngularJS with nested functions

Currently, I'm tackling a small project with AngularJS and finding myself tangled in multiple asynchronous calls that are starting to become chaotic. I know there must be a more efficient way to handle these calls, but I'm unsure of the best appr ...

Unlock the full potential of integrating external APIs with Next.js

As a newcomer to NextJs, I am facing the task of making calls to an external Python API from my frontend. Upon discovering NextJs's integrated API feature through creating folders in the app directory, namely api/resource/route, I am wondering what th ...

Creating a rhombus or parallelogram on a canvas can be easily achieved by following these simple

I'm new to working with the canvas element and I want to create some shapes on it. Can someone provide me with guidance on how to draw a Rhombus or Parallelogram on a canvas? Something similar to what is shown in this image: https://i.stack.imgur.c ...

Exploring Ways to Navigate to a Component Two Steps Back in Angular

Let's say I have three routes A->B->C. I travel from A to B and then from B to C. Now, is it possible for me to go directly from C to A? ...

Unable to add key/value pair to object in Node

While using Node, I encountered a strange issue where I was unable to attach the key/value pair broadcastStamp = date to the object "result." Despite confirming that it is indeed an object with typeof, no errors were thrown - the key/value simply did not a ...

What is the process for changing and updating the key of an object based on comparisons with other objects?

My task involves working with an array of objects that contain unique IDs as keys. const sampleObj1 = {0011:[{},{}], 0022:[{}, {}], 0033:[{},{}]} const sampleObj2 = [{id:0011, name:'test1'}, {id:0022, name:'test2'}, {id:0033, name:&apos ...

Is there a way to automatically launch a new tab upon arriving from another website?

I currently have a website that displays a table of elements, each with its own set of sub-elements. On another page, I can view the element along with multiple tabs for its corresponding sub-elements. The current setup is depicted as follows: <a clas ...

Issue with Setting Value in JQuery Select Box

I am in the process of designing a webpage that allows users to edit listings they have created on my website. These listings fall under three main categories, each with its own set of subcategories. To streamline this process, I am implementing AJAX to dy ...

Ways to align and fix a button within a specific div element

How can I make the button with position: fixed property only visible inside the second div and not remain fixed when scrolling to the first or last div? .one{ height:600px; width: 100%; background-color: re ...