为什么在此示例中,Angular js路由不起作用?

编程入门 行业动态 更新时间:2024-10-28 06:23:33
本文介绍了为什么在此示例中,Angular js路由不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在学习angular js中的路由,请通过以下示例帮助我.在此示例中,路由不起作用.我需要在任何服务器上运行它吗?

I am learning routing in angular js, please help me with following example. Routing is not working in this example. Do I need to run this on any server?

<!DOCTYPE html> <html> <script src="ajax.googleapis/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <script src="//ajax.googleapis/ajax/libs/angularjs/1.4.8/angular-route.js"></script> <body ng-app="myApp"> <p><a href="#/">Main</a></p> <a href="#/red">Red</a> <a href="#/green">Green</a> <a href="#/blue">Blue</a> <div ng-view></div> <script> var app = angular.module("myApp", ["ngRoute"]); app.config(function($routeProvider) { $routeProvider .when("/", { templateUrl : "main.html" }) .when("/red", { templateUrl : "red.html" }) .when("/green", { templateUrl : "green.html" }) .when("/blue", { templateUrl : "blue.html" }); }); </script> <p>Click on the links to navigate to "red.htm", "green.htm", "blue.htm", or back to "main.htm"</p> </body> </html>

main.html

main.html

<h2> Hello this is main.html</h2>

red.html

<h2> Hello this is red.html</h2>

green.html

green.html

<h2> Hello this is green.html</h2>

blue.html

blue.html

<h2> Hello this is blue.html</h2>

推荐答案

尝试将URL用作

<p><a href="/">Main</a></p> <a href="/red">Red</a> <a href="/green">Green</a> <a href="/blue">Blue</a>

然后只有您的路线婴儿车设置有您的网址

Then only your route prams set with your URL

更多推荐

为什么在此示例中,Angular js路由不起作用?

本文发布于:2023-11-15 07:03:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1592209.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在此   示例   路由   不起作用   Angular

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!