At the moment the problem is that, if you try to navigate to a route that is not configured, you will see only the layout page without any partial template injected into it. 

For example if you navigate to http://localhost:51983/ABC, since ABC is not a configured route you will see the layout page (index.html) as shown below. 
 


You will also have this same problem if you navigate to the root of the site i.ehttp://localhost:51983. The reason angular is displaying the empty layout template in both these cases, is because it does not know what partial template to inject. We want angular to redirect to default route if the user is trying to navigate to a route that is not configured. 

How to configure the default route in Angular : Well that is straight forward. All you need is the following line in config() function in script.js file

.otherwise({
redirectTo: "/home"
})

With the above change the code in config() function should be as shown below.

.config(function ($routeProvider, $locationProvider) {
$routeProvider
.when("/home", {
templateUrl: "Templates/home.html",
controller: "homeController"
})
.when("/courses", {
templateUrl: "Templates/courses.html",
controller: "coursesController"
})
.when("/students", {
templateUrl: "Templates/students.html",
controller: "studentsController"
})
.otherwise({
redirectTo: "/home"
})
$locationProvider.html5Mode(true);
})

With this change if the user tries to navigate to a route that is not configured (http://localhost:51983/ABC) or just to the rooot URL (http://localhost:51983), the user will be automatically redirected to http://localhost:51983/home.

Part 28 AngularJS default route的更多相关文章

  1. Default route and zero route

    A default route of a computer that is participating in computer networking is the packet forwarding ...

  2. FreeBSD Set a Default Route / Gateway

    Task: View / Display FreeBSD Routing Table Use netstat command with -r option:$ netstat -r$ netstat ...

  3. 永久改动redhat的default route

    1,能够用route命令暂时改动: route add default gw <gateway ip> 2, 通过改动/etc/sysconfig/network 文件永久改动: 脚本: ...

  4. 【angularJS】Route路由

    介绍 AngularJS 路由允许我们通过不同的 URL 访问不同的内容. 通过 AngularJS 可以实现多视图的单页Web应用(single page web application,SPA). ...

  5. angularJS中-$route路由-$http(ajax)的使用

    后台请求使用的是nodeJS驱动(后面帖代码),很简单的RESTFUL, 页面使用的是bottstarp3.0(懒人神器); 第一个例子: 在本地架设NODEJS, angular的所有请求都是请求本 ...

  6. [AngularJS] Default Child state and nav between child state

    Let's say we want a parent state which is a abstract state. Two children states, one is for sinlge a ...

  7. AngularJS中Route例子

    代码:https://files.cnblogs.com/files/xiandedanteng/angularJSRouteSample.rar 点击‘首页’后: 点击‘电脑’后: <!DOC ...

  8. 002 static and default route

    r2(config)#ip route 192.168.1.0 255.255.255.0 192.168.2.1 r1(config)#ip route 192.168.3.0 255.255.25 ...

  9. Change Default Route

    route delete 0.0.0.0route add 0.0.0.0 mask 0.0.0.0 10.226.4.14

随机推荐

  1. Python第3方模块安装

    前言: 我们在实际开发过程中,很多模块是Python没有自带的,所以我们使用模块前需要先安装第三方模块. 在线安装: 1.为了简便cmd指令操作,建议先打开Python目录下的Scripts文件夹下, ...

  2. Winform配置文件读写操作

    前言 在项目当中为了增加软件的灵活性及可配置性,配置文件在程序当中起着不可替代的作用.下面介绍一下最近用的比较多的方式. config文件的操作 数据库连接字符串 1.获取连接字符串 public s ...

  3. pandas 基础命令

    参考链接:https://github.com/rmpbastos/data_science/blob/master/_0014_Boost_your_Data_Analysis_with_Panda ...

  4. kafka高可用探究

    kafka高可用探究 众所周知 kafka 的 topic 可以使用 --replication-factor 数和 partitions 数来保证服务的高可用性 问题发现 但在最近的运维过程中,3台 ...

  5. Skywalking-12:Skywalking SPI机制

    SPI机制 基本概述 SPI 全称 Service Provider Interface ,是一种服务发现机制.通过提供接口.预定义的加载器( Loader )以及约定俗称的配置(一般在 META-I ...

  6. centos7有关于防火墙的命令

    查看防火墙状态 firewall-cmd --state 开启防火墙 systemctl start firewalld.service 关闭防火墙 systemctl stop firewalld. ...

  7. oracle查看和修改session和最大连接数

    第一步,在cmd命令行,输入sqlplus 第二步,根据提示输入用户名与密码 1. 查看processes和sessions参数 SQL> show parameter processes NA ...

  8. .NET 开发一个服务器 应用管理工具

    一:背景 1.Anno.Deploy Anno.Deploy可以和 Anno集成使用,用于部署新的服务.启动服务.停止服务.清理服务.也可以单独使用,用于守护程序. 使用方法 1.和Anno集成使用 ...

  9. caffe转换变量时的gflags问题

    先解决错误7,解决方式来自于http://blog.csdn.net/wishchin/article/details/51888566这篇博文,感谢博主 只需要添加上 #pragma comment ...

  10. java语言程序设计与数据结构(基础篇)第二章答案

    答案为本人自己求解,若有错误,还望海涵并及时告知.如有雷同,纯属巧合. 2.1 import java.util.Scanner; public class Welcome { public stat ...