2

I'm trying to route an extremely simple example component in AngularJS 1.5.8. Spent about two days trying different things but am down to this extremely simple example.

I've tried using ui-view name="main". Also tried changing the URL from '/' to something else like '/path' but browser comes back with 'Cannot GET /path'. So it shows me that the routing isn't working at all. Also tried NOT using a component route and changed to a template. Still doesn't work (white page with no console errors in browser).

Using angular-ui-router v1.0.0-beta

app.module.js

    (function(){

    'use strict';
    angular.module('mainApp', ['ui.router'])

        .component('mainComponent', {
            controller: function(){
                this.message = "message from the controller";
            },
            template: 'sample template from app component'
        })

        .config(function($stateProvider){

            var mainState = {
                name: 'main',
                url: '/',
                component: 'mainComponent'
            };

            $stateProvider.state(mainState);

        });
})();

index.html

<!DOCTYPE html>
<html lang="en" >

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>SB Admin 2 - Bootstrap Admin Theme</title>

    <!-- Bootstrap Core CSS -->
    <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link href="vendor/metisMenu/metisMenu.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="dist/css/sb-admin-2.css" rel="stylesheet">

    <!-- Morris Charts CSS -->
    <link href="vendor/morrisjs/morris.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.33.3/es6-shim.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.20/system-polyfills.js"></script>
        <script src="https://npmcdn.com/angular2/es6/dev/src/testing/shims_for_IE.js"></script>
    <![endif]-->


    <!-- jQuery -->
    <script src="vendor/jquery/jquery.min.js"></script>

    <!-- AngularJS -->
    <script src="bower_components/angular/angular.min.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="vendor/bootstrap/js/bootstrap.min.js"></script>

    <!-- Metis Menu Plugin JavaScript -->
    <script src="vendor/metisMenu/metisMenu.min.js"></script>

    <!-- Custom Theme JavaScript -->
    <script src="dist/js/sb-admin-2.js"></script>

    <!-- Component Router -->
    <script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>

    <!-- SPA Resources -->
    <script src="app/app.module.js"></script>


</head>

<body ng-app="mainApp">
    <ui-view></ui-view>

</body>

</html>
2
  • jsfiddle.net/yaprak/789Ks/1 Commented Dec 26, 2016 at 4:56
  • @M14 Was looking for routing to component etc {url: "#", component: "compName"} Commented Dec 26, 2016 at 5:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.