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

Data retrieval is currently not functioning, as React is not displaying any error messages

One of the components in my app is as follows: import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { compose } from 'redux'; import { translate ...

leveraging the localStorage feature in a for-in iteration

I am new to stackOverflow, although I have browsed the forums for help in the past. However, this time I couldn't find a solution to my current issue, so I decided to create an account and seek assistance. The problem at hand is related to a workout ...

javascript passing a window object as an argument to a function

In Slider function, I am passing a window object that does not contain the body element. Additionally, my code only functions correctly on mobile screens. While debugging the code below: console.log(windows.document); If (!mySlider) {console.log(windows. ...

Run code from an inline script that is retrieved from an external origin

I am encountering an issue with my React app where I need to fetch index.html from one server location and run its scripts from another server location: const entries = await axios.get(`http://localhost:xxx`); let domParser = new DOMParser(); let tempDO ...

Adjust words to fit any screen size as needed

Looking for a small program that can dynamically change a word within an SVG? The goal is to create an effect where regardless of the word or group of words, they always stretch along the entire height (due to a 90-degree rotation) by adjusting the font si ...

List component in Angular not refreshing after sorting the array in the service

Currently, I am delving into the realm of Angular (version 5+) to enhance my skills by working on a small project. The project involves setting up basic routing functionalities to showcase the ContactList component upon selecting a navigation tab. Addition ...

Design an interactive div element that allows users to modify its content, by placing a span

Here is an example of the desired effect: ICON LINE - 1 This is some sample text inside a div element and the next line should begin here ICON LINE - 2 This is some sample text inside a div element a ...

When executed, the Node application successfully compiles

I have a TypeScript application that runs smoothly in development mode using ts-node. However, after building the application, I encounter some unexpected warnings and errors. This is my tsconfig.json: { "compilerOptions": { "incremen ...

React Material Table - issue with data filtering accuracy

Currently in my React project, I am utilizing Material Table. While everything appears to be rendering correctly, the filtering and searching functionalities are not working as expected. To provide more context, below is a sample of the code: ht ...

difficulty encountered during json parsing

I need help accessing displayName in req When I use this code snippet: console.log(req.session.passport.user._raw) The following information is displayed: { "kind": "plus#person", "etag": "\"ucaTEV-ZanNH5M3SCxYRM0QRw2Y/XiR7kPThRbzcIw-YLiAR ...

What is the most effective approach for delivering arguments to event handlers?

Consider the following block of HTML: <button id="follow-user1" class="btnFollow">Follow User1</button> <button id="follow-user2" class="btnFollow">Follow User2</button> <button id="follow-user3" class="btnFollow">Follow User ...

The tool tip feature is not recognizing line breaks

I've encountered an issue with the tooltip in my project. Despite trying various solutions found on stackoverflow, I am still unable to resolve it. In my ReactJS application, I am dynamically creating elements using createElement and applying the too ...

Access to REST API is restricted

Working on an AngularJS client alongside a node REST service has presented me with a challenge. Upon attempting to utilize the REST service on my local machine, I encountered the following error: XMLHttpRequest cannot load http://tasks.dev:12345/articles. ...

Display a fixed three levels of highchart Sunburst upon each click in Angular8

Looking to create a dynamic sunburst highchart that displays three levels at a time while allowing interactive drilling. For instance, if there are 5 levels, the chart should initially show the first three levels. When clicking on level 3, levels 2, 3, and ...

Tips for including multiple JSON results into a single text box for auto-complete purposes

I am trying to combine different autocomplete list results into one text box. It's straightforward to use separate text boxes for different autocomplete results. HTML: <input id="university" name="university" type="text" /> <input id="unive ...

Turning a JavaScript function into jQuery

Is there a way to convert this JavaScript selected code into jQuery? I need to target a button class instead of an ID, and I've heard that using jQuery is the simplest way to achieve this. var playButton1 = $('.playButton1'); playButton1.o ...

Webpage Text Animation

This is the visual representation of my webpage: https://i.stack.imgur.com/tYq34.png I am seeking to implement a uniform animation effect for the text "Carlos Qiano" and "Lorem Ipsum", similar to the link below: https://i.stack.imgur.com/XVnBS.jpg Note: ...

Is it necessary to decode the JSON data stored in the variable?

Consider the code snippet below: var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { var responses = JSON.parse(this.responseText); var ...

What is the importance of utilizing `document.createElementNS` when incorporating `svg` elements into an HTML webpage using JavaScript?

Not Working Example: const svg = document.createElement('svg') svg.setAttribute('height', '100') svg.setAttribute('width', '100') document.body.appendChild(svg) const rect = document.createElement(&apos ...

Ways to add a string to an array as a labeled object in javascript?

Is there a way to manipulate the array in imageCollection to achieve the format of the array in carouselPhotos as shown below? export default class HomeScreen extends Component { state = { imageCollection: [ { name: "P ...