javascript - AngularJS loads only the component html instead of entire ng-view
问题描述
I created routes, and one route which can hold the params and upon them call the specific html in ng-view.
<div id="navPost" class="row">
<div class="col-sm-8">
<div class="levakolona">
<main ng-view></main>
</div>
</div>
<div class="col-sm-4">
<div class="desnakolona">----
// something
</div>
</div>
</div>
And here are the routes...
app.config(['$routeProvider', '$locationProvider',function($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$locationProvider.hashPrefix('!');
$routeProvider
.when("/",
{
title: 'Glavna',
templateUrl : "/pages/kartice.html",
controller: 'kontroler'
})
.when("/glavna",
{
title: 'Glavna',
templateUrl : "/pages/kartice.html",
controller: 'kontroler'
})
.when("/post/:postID",
{
title: 'Post',
templateUrl: '/pages/post.html',
controller: 'kontroler'
})
.when("/o-nama",
{
title: 'Post',
templateUrl: '/pages/Onama.html',
controller: 'kontroler'
})
.otherwise({
redirectTo: '/'
});
}]);
app.controller('kontroler', ['$scope', '$routeParams', function($scope, $routeParams){
$scope.templateUrl = '/pages/postovi/'+$routeParams.postID + '.html';
}]);
When i route with /post/VaricellaZoster.html it opens me that specific html in post.html and calls back to ng-view...but when i type that url directly in Chrome or whatever browser then it opens me just that html and doesn't generate entire app with ng-view...and how can it can be fixed?
解决方案
Add in your htaccess:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /index.html [NC,L]
This will skip to the actual resource if there is one, and to index.html for all AngularJS routes.
推荐阅读
- javascript - 正则表达式检查两个字符在字符串中的数量是否相同
- azure-active-directory - 使用从 Azure API 管理转发的站点处理 AAD 登录
- javascript - 用 Playwright 进行屏幕截图测试的好方法是什么?
- python-3.x - Python/Selenium - 在字符之前打印元素的文本
- go - 教我 Go 包、导入和原型
- python - 这个字符串格式是什么意思:(return f"${value:,.2f}")
- json - 如何将powershell中的对象序列化为json并在PS桌面和核心中获得相同的结果?
- python - '%config InlineBackend.figure_format = 'svg'' 不适用于 Python3.5
- android - 写入权限不起作用 - 范围存储 Android SDK 30(又名 Android 11)
- node.js - 为什么我的错误处理程序不处理异步中间件抛出的异常?