我正在尝试实现named routes,所以我不必编写整个路径(经常更改).
我以为我可以逃避编写一个服务,该服务将返回已定义路由的列表以及将对象转换为路径的过滤器
使用示例如下所示:
<a ng-href="{id:1}|route:'detail'">Click here!</a>
Run Code Online (Sandbox Code Playgroud)
如果我在路由定义中添加了名称:'detail',则会产生以下结果:
<a href="#/detail/1/">Click here!</a>
Run Code Online (Sandbox Code Playgroud)
我认为这很简单,但是:
如何获取已定义路线的列表?
我以为我可以使用routeProvider,但AFAIK它没有我可以访问的公共方法或属性.
我正在尝试将Lazy Loading实现到我的应用程序中,但似乎遇到了一个问题,我得到了错误消息:
// External Dependencies
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
// Internal Dependencies
import { MaterialModule } from '../app/configuration/material/material.module';
import { SharedModule } from '../app/application/shared/shared.module';
import { RoutingModule } from '../app/configuration/routing/routing.module';
import { SettingsModule } from '../app/application/settings/settings.module';
import { AppComponent } from './app.component';
import { SearchService } from './application/shared/services/search.service';
@NgModule({
declarations: [AppComponent],
imports: [ …Run Code Online (Sandbox Code Playgroud) 在Angular.js路由上阅读了大量的报告和stackoverflow问题之后,当我进行手动刷新时,我仍然收到"未找到"错误.
脚步:
localhost- >因为我的配置(下面),我被带到了localhost/home.视图和一切都很好.Not Found: the requested /home is not found on this server这个问题可能最像刷新页面给出"找不到页面"
我的配置
// Routing configuration.
angular.module('myModule')
.config(['$routeProvider', '$locationProvider',
function ($routeProvider, $locationProvider) {
// Enable pushState in routes.
$locationProvider.html5Mode(true);
$routeProvider
.when('/home', {
templates: {
layout: '/views/home.html'
},
title: 'Welcome!'
})
.when('/launchpad', {
templates: {
layout: '/views/layouts/default.html',
content: '/views/partials/profile.html'
},
title: "Launchpad"
})
.otherwise({
redirectTo: '/home'
});
}
]);
Run Code Online (Sandbox Code Playgroud)
我做过的其他事情:
index.html,我已经有了<base href="/">这是我尝试过的htaccess规则.没有工作.
我正在使用angularJSAJAX构建一个简单的单页面应用程序,但是当用户使用本机后退按钮时,我遇到了问题.
angular.module('myApp', ['ionic', 'myApp.controllers', myApp.services])
.config(function ($routeProvider, $locationProvider) {
$routeProvider.when('/home', {
templateUrl: 'templates/feed.html',
controller: 'MenuCtrl',
reloadOnSearch: false
});
$routeProvider.when('/checkin/view/:id', {
templateUrl: 'templates/checkin.html',
controller: 'MenuCtrl'
});
$routeProvider.otherwise({
redirectTo: '/home'
});
$locationProvider.html5Mode(true)
})
Run Code Online (Sandbox Code Playgroud)
更新:每个反馈移出$ http控件,并提出建议:
我的services.js档案:
angular.module('myApp.services', [])
.factory('FeedService', ['$http', function($http){
var state = {};
var loadFeed = function(){
$http({
method: 'GET',
url: 'http://api.example',
}).success(function(data){
// With the data succesfully returned, call our callback
state = data.response;
console.log(data);
}).error(function(){
alert("error");
});
};
loadFeed();
return {
getState: function(scope){
return …Run Code Online (Sandbox Code Playgroud) 我已经从"beta.17"更新为"2.0.0-rc.1",我不明白何时应该使用路由器以及何时使用路由器?
我正在尝试用角度2创建一个应用程序,并且想要传递params来标记[routerLink]中的一个,我想要像这样的链接:
<a href="/auth/signup?cell=1654654654"></a>
Run Code Online (Sandbox Code Playgroud)
我不知道如何传递cell模板......
我有导入:
import { RouterModule, Routes} from '@angular/router';
Run Code Online (Sandbox Code Playgroud)
然后我在我的函数内部组件中使用了以下行
this.router.navigate(['/dashboard']);
Run Code Online (Sandbox Code Playgroud) 如何修复路由?我有一个带有Angular前端的C#项目.如果我去ac #View哪个调用Angular组件,一切都会中断.如果我调用Angular视图(直接从URL),一切正常.
C#路由到ac#视图
xxx/Home/index 这只是一个调用Angular组件的View(抛出一堆500个错误)手动路由到Angular
/anything到url(xxx/Home/Index/anything),Angular路由接管并且所有内容都加载正常.索引方法调用
public class HomeController : Controller
{
public IActionResult Index()
{
return View("IndexAng");
}
}
Run Code Online (Sandbox Code Playgroud)
IndexAng.cshtml
@{
ViewData["Title"] = "Home Page";
}
@*<script src="https://npmcdn.com/tether@1.2.4/dist/js/tether.min.js"></script>*@
@*<app asp-prerender-module="ClientApp/dist/main-server">Loading...</app>*@
<h3>Loading Ang App root:</h3>
<app-root></app-root>
<script src="~/dist/vendor.js" asp-append-version="true"></script>
@section scripts {
<script src="~/dist/main-client.js" asp-append-version="true"></script>
}
Run Code Online (Sandbox Code Playgroud)
从Startup.cs配置方法
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbContext identityContext,
UserManager<ApplicationUser> userManager, RoleManager<IdentityRole> roleManager)
{
#if DEBUG
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
{
HotModuleReplacement = true …Run Code Online (Sandbox Code Playgroud) 我现在从头开始开发基本应用程序时遇到一个奇怪的错误。我使用Ionic 4 beta 19,并已将routerLink放置到另一个页面,该路由是在基本页面模块中设置的,如下所示:
RouterModule.forChild([
{ path: '', component: NewsPage },
{ path: ':id', component: DetailPage }
])
Run Code Online (Sandbox Code Playgroud)
routerLink属性是在卡上设置的,单击卡时它可以正常工作,但是当我返回并按同一张卡或另一张卡时,路由器根本不执行任何操作。我没有任何错误,浏览器中的URL正常运行。怎么会这样?
编辑:此外,DetailPage没有模块,因此它基本上只是一个页面。
编辑:卡代码如下所示:
<ion-card *ngFor="let item of items;" [routerLink]="[item.id]">
...
</ion-card>
Run Code Online (Sandbox Code Playgroud)
在详细信息页面中,路由参数已预订,而:id参数将用于GET请求预订以检索数据
我在 Mac 环境下成功创建了一个 angular 项目
Angular CLI: 7.0.5
Node: 8.11.3
OS: darwin x64
Angular: 7.0.3
Run Code Online (Sandbox Code Playgroud)
现在我在 ubuntu 18.04 上使用设置运行相同的代码
Angular CLI: 7.3.9
Node: 12.9.1
OS: linux x64
Angular: 7.2.15
Run Code Online (Sandbox Code Playgroud)
但是在尝试延迟加载另一个模块时出现了一个非常奇怪的问题,我不断收到此错误错误:找不到模块“app/website/site.module”
这是我的项目结构
和 app-routing.module.ts
const routes: Routes = [
{
path: 'site',
loadChildren: 'app/website/site.module#SiteModule',
}
]
Run Code Online (Sandbox Code Playgroud)
路由用于在mac中工作但在ubuntu中失败
我查了一个不同的解决方案
const rootRoutes: Routes = [
{ path: 'site', loadChildren: './website/site.module#SiteModule' }
];
Run Code Online (Sandbox Code Playgroud)
但它仍然无法正常工作。
angular-routing ×10
angular ×7
angularjs ×3
.htaccess ×1
ajax ×1
c# ×1
ionic4 ×1
javascript ×1
jquery ×1
routing ×1