当前位置:主页 > 网页前端 > JavaScript代码 >

JS路由跳转的简单实现代码

时间:2021-08-24 08:47:29 | 栏目:JavaScript代码 | 点击:

这是一个简单的路由跳转,希望对你有所帮助

下面的连接中有复杂的路由跳转

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <script src="angular1.4.6.min.js"></script>
  <script src="angular-route.js"></script>
</head>
<body ng-app="MyApp" >
<a href="#/" rel="external nofollow" >CHINA</a><br/>
<a href="#/1" rel="external nofollow" >CHINA1</a><br/>
<a href="#/2" rel="external nofollow" >CHINA2</a><br/>
<a href="#/3" rel="external nofollow" >CHINA3</a><br/>
<div ng-view>
11111
</div>
<script>
  var app = angular.module("MyApp", ["ngRoute"]);
  app.config(function ( $routeProvider) {
    $routeProvider
      .when("/", {template: "<h1>123</h1>"})
      .when("/1", {template: "<h1>111</h1>"})
      .when("/2", {template: "<h1>222</h1>"})
      .when("/3", {template: "<h1>333</h1>"});
  });
</script>
</body>
</html>

总结

您可能感兴趣的文章:

相关文章