SPA单页路由词典

一、angular

<!doctype html>

<html ng-app="myApp">

<head lang="zh">

<meta charset="utf-8">

<script src="angular.js"></script>

<script src="angular-route.js"></script>

<title>ng</title>

</head>

<body>

<div ng-view></div>                                //容器

<script>

var app=angular.module('myApp',['ng','ngRoute']);

app.config(function($routeProvider){
$routeProvider.when('/login',{templateUrl:'tpl/login.html'})

  .when('/register',{templateUrl:'tpl/register.html'})

.otherwise({redirectTo:'/login'})

});

</script>

</body>

</html>


二、ionic

<!doctype html>
<html ng-app="myApp">
<head lang="en">
  <script src="ionic.bundle.js"></script>
  <meta charset="UTF-8">
  <title>ionic</title>
</head>
<body>
  <ui-view></ui-view>                              //容器
<script>
  var app = angular.module('myApp',
      ['ionic']);
  //配置状态
  app.config(
      function ($stateProvider,
                $urlRouterProvider) {
        //添加状态
        $stateProvider
            .state('start', {
              url: '/myStart',
              templateUrl: 'tpl/start.html'
            })
            .state('login', {
              url: '/myLogin',
              templateUrl: 'tpl/login.html',
              controller: 'loginCtrl'
            })
            .state('main', {
              url: '/myMain/:myName',  //有参数
              templateUrl: 'tpl/main.html',
              controller: 'mainCtrl'
            })
        //默认链接
        $urlRouterProvider
            .otherwise('/myLogin');
      })

</script>

</body>

</html>


三、vue

<!doctype html>
<html>
<head lang="en">
  <meta charset="utf-8">
  <script src="js/vue.js"></script>
  <script src="js/vue-router.js"></script>
  <title></title>
</head>
<body>
<div id="example">
  <router-view></router-view>      //容器
</div>
<script  id="myLogin"  type="text/x-template">
    <div>
      <h1>这是登录页面</h1>
      <button @click="jump">
        没有账号去注册
      </button>
      <a href="#/kflRegister">
        去注册
      </a>
      <!-- 通过路由插件的指令-->
      <router-link
          to="/kflRegister">
        再去注册
      </router-link>
    </div>
</script>
<script id="myRegister" type="text/x-template">
    <div>
      <h1>这是注册页面</h1>
    </div>
</script>
<script>
  var MyLogin = Vue.component('login',{
    template:'#myLogin',
    methods:{
      jump: function () {
        //借助于路由模块 实现组件间的跳转
        this.$router
            .push('/kflRegister');
      }
    }
  })
  var MyRegister = Vue.component('register',{
    template:'#myRegister'
  })
  //配置路由词典
  const myRoutes = [
    {
      path:'/kflLogin',
      component:MyLogin
    },
    {
      path:'/kflRegister',
      component:MyRegister
    },
    {
      path:'',
      component:MyLogin
    }
  ];
  const myRouter = new VueRouter({
    routes:myRoutes
  })
  new Vue({
    router:myRouter,
    el: '#example',
    data: {
      msg: 'hello'
    }
  })
</script>
</body>
</html>



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值