路由页面导航

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="angular-1.3.0.js"></script>
    <script src="angular-route.js"></script>
<body ng-app='routeDemo'>
<!--左边栏-->

<div id="navigator">
    <!--菜单-->
    <table style=" width: 250px; height: 40px; margin: auto;">
        <tr>
            <td><a href="#/home">商品列表</a></td>
            <td><a href="#/woman">用户信息</a></td>
            <td><a href="#/man">地址信息</a></td>

        </tr>
    </table>

</div>
<!--下边栏-->
<div style="width: 300px;display: inline-block;height: 400px;">
    <div ng-view="" ></div>
</div>
</body >

    <script type="text/ng-template" id="index.home.html">
      <ul  style="list-style-type:none;margin: auto;">
        <li>外星人</li>
        <li>联想</li>
        <li>三星</li>
        <li>苹果</li>
      </ul>
    </script>
    <script type="text/ng-template" id="index.woman.html">
        <ul  style="list-style-type:none; margin: auto;">
        <li>张三</li>
        <li>李四</li>
        <li>王五</li>
        <li>赵六</li>
        </ul>
    </script>
    <script type="text/ng-template" id="index.man.html">
        <ul  style="list-style-type:none; margin: auto;">
        <li>上地一街</li>
        <li>上地二街</li>
        <li>上地三街</li>
        <li>上地四街</li>
        </ul>
    </script>

    <script type="text/javascript">
        angular.module('routeDemo',['ngRoute'])
            .controller('HomeController',function ($scope,$route) {
                $scope.$route = $route;
            })
            .controller('WomanController',function ($scope,$route) {
                $scope.$route = $route;
            })
            .controller('WomanController',function ($scope,$route) {
                $scope.$route = $route;
            })
            .controller('ManController',function ($scope,$route) {
                $scope.$route = $route;
            })


            //配置$routeProvider用来定义路由规则
            //$routeProvider为我们提供了when(path,object)& other(object)函数按顺序定义所有路由,函数包含两个参数:
            //@param1:url或者url正则规则
            //@param2:路由配置对象
            .config(function($routeProvider){
                $routeProvider.
                when('/home',{
                    //templateURL:插入ng-view的HTML模板文件
                    templateUrl:'index.home.html',
                    controller:'HomeController'

                }).
                when('/woman',{
                    templateUrl:'index.woman.html',
                    controller:'WomanController'
                }).
                when('/man',{
                    templateUrl:'index.man.html',
                    controller:'ManController'
                })

            })
    </script>

</html>
在Vue 3.0中,你可以使用Vue Router来进行页面导航。Vue Router是Vue官方提供的路由管理工具,它能够帮助你在Vue应用中实现页面的切换和导航。 下面是一个通俗的讲法来进行Vue 3.0中的路由页面导航: 1. 首先,你需要安装Vue Router。你可以通过npm或者yarn来安装它。在你的项目根目录下运行以下命令安装Vue Router: ```shell npm install vue-router ``` 2. 安装完成后,在你的Vue应用中导入Vue Router,并创建一个路由实例。 ```javascript import { createRouter, createWebHistory } from 'vue-router' import Home from './components/Home.vue' import About from './components/About.vue' const router = createRouter({ history: createWebHistory(), routes: [ { path: '/', component: Home }, { path: '/about', component: About } ] }) ``` 在这个例子中,我们创建了一个路由实例,并定义了两个路由规则。当访问根路径 `/` 时,会渲染 `Home` 组件;当访问 `/about` 路径时,会渲染 `About` 组件。 3. 在你的Vue应用中,使用 `<router-view>` 组件来显示当前路由对应的组件。 ```html <router-view></router-view> ``` 4. 最后,将路由实例挂载到Vue应用中。 ```javascript import { createApp } from 'vue' import App from './App.vue' const app = createApp(App) app.use(router) app.mount('#app') ``` 在这个例子中,我们使用 `app.use(router)` 来安装路由实例到Vue应用中。 现在,你就可以通过改变URL或者通过编程导航(例如点击一个按钮)来切换页面了。Vue Router会自动根据URL的变化来匹配对应的路由规则,并渲染相应的组件。 希望这个通俗的讲法能够帮助你理解在Vue 3.0中如何进行路由页面导航!如果你还有其他问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值