gpt4 book ai didi

javascript - Angular 中的清理 URL

转载 作者:行者123 更新时间:2023-11-29 21:17:11 24 4
gpt4 key购买 nike

我有一个名为 home.html 的部分网页。当我在 chrome 中运行页面时,地址显示为 http://127.0.0.1:63342/Angular-01/htmlPage1.html?_ijt=vfdcblvb6ahn0t6et7rv6k8tm0#/home我应该在哪里看到一个更清晰的网址(没有扩展名)。我已将我的路线配置为:

var myApp = angular.module("myModule", ["ngRoute"])
.config(function ($routeProvider) {
$routeProvider
.when("/home", {
templateUrl: "views/home.html",
controller: "homeController"
})
})
.controller("homeController", function ($scope) {
$scope.message = "Home page";
})

如何实现?

最佳答案

当使用 Angular 路由时,您不需要像调用 home.html 那样调用静态页面。你只需运行你的应用程序并说你想回家, Angular 路由将带你到 home.html

When I run the page in chrome? If you open only a static html page in browser it will serve you only that page not the angular application

为了运行整个 Angular 应用程序

如果您使用 http-server 或任何其他节点服务器运行您的应用程序,您需要为整个 Angular 应用程序提供服务,然后将加载 index.html,这将加载您的 Angular 应用程序,您的配置函数将被调用,它将寻找请求并给你 View

Note:- you need to put <div ng-view></div> for routing

关于javascript - Angular 中的清理 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38985029/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com