文档https://angular.io/docs/ts/latest/guide/router.html说明
...默认情况下,当路由器重新导航到相同的组件类型而不首先访问不同的组件时,会重用组件实例。每次重复使用之间参数可能会发生变化...
但没有提示如何更改此默认行为。
是否可以防止重复使用?
我想创建一个具有动态路由的项目,该项目仅在 url 上键入名称,然后路由将检测 url 并创建对该文件的自己的路由访问以显示给浏览器
import { Routes,RouterModule } from '@angular/router';
const routes: Routes= GetDynamicRoute();
export const routing = RouterModule.forRoot(routes);
function GetDynamicRoute(){
var results :Array<Object> = Array<Object>();
var page = 'GET_URL_PARAMATER';
results.push({ path: '' ,loadChildren: 'app/tmp/home.module'});
results.push({ path: page, loadChildren: 'app/tmp/'+page+'.module' })
return results
}
Run Code Online (Sandbox Code Playgroud) 我遇到了 Angular2 删除尾部斜杠的问题。我已经设置了我的 dotnet core 应用程序来添加它们,但是一旦加载了 js,它们就会被删除。
在 Angular2 中可能吗?
(我的客户需要它,所以不需要添加注释;不要使用尾部斜杠)。
提前致谢。
编辑:应该添加,这是与 Angular2-Universal 一起运行的,所以升级 Angular 版本并不那么容易:(
我在我的 angular 4 项目中使用 bootstrap3。我有一个 DashboardComponent,其中包含一个导航菜单。我将一条路线声明为
{path: 'dashboard', loadChildren: 'app/dashboard/dashboard.module#DashboardModule'}
Run Code Online (Sandbox Code Playgroud)
在路由模块和引导程序导航菜单中未正确显示。如果我将路由配置更改为
{path: 'dashboard', component: DashboardComponent}
Run Code Online (Sandbox Code Playgroud)
那么它的工作正常。
以下是工作和非工作情况的屏幕截图。我能解决什么问题?
dashboard-routing.module.ts
export const dashboardRoutes: Route[] = [
{
path: '',
component: DashboardComponent,
children: [
{ path: 'home', component: HomeComponent },
{ path: 'dispatches', component: DispatchesComponent },
{ path: '', component: HomeComponent }
]
}
]
@NgModule({
imports: [
RouterModule.forChild(dashboardRoutes)
],
exports: [RouterModule]
})
export class DashboardRoutingModule { }
Run Code Online (Sandbox Code Playgroud)
这里是 dashboard.component.html
<div class="wrapper">
<div class="sidebar" data-color='red' data-image="" style="overflow: hidden;">
<sidebar-cmp></sidebar-cmp>
<div class="sidebar-background" …Run Code Online (Sandbox Code Playgroud) twitter-bootstrap twitter-bootstrap-3 angular2-routing angular
我正在阅读Angular 2 Tour of Heroes教程的第 7 部分。在包含 InMemoryWebApiModule 之后hero.service.ts使用private heroesUrl = 'api/heroes';.
应用程序如何知道 WebAPI url 是api/heroes?我在app-routing.module.ts. 映射到 InMemoryWebApiModule 的 url 是如何工作的?
我已经按照此模板使用 angular 2 创建了 asp.net mvc 应用程序
我的应用程序:
索引.cshtml
@{
Layout = null;
ViewBag.Title = "Home Page";
}
<!DOCTYPE html>
<html>
<head>
<base href="@Url.Content("~/")">
<title>MVC 4 Angular 4</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="dist/scripts/packages/core-js/client/shim.min.js"></script>
<script src="dist/scripts/packages/zone.js/dist/zone.js"></script>
<script src="dist/scripts/packages/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('dist/scripts/main.js').catch(function (err) {
console.error(err);
});
</script>
</head>
<body>
<my-app>Loading...</my-app>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
主文件
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
Run Code Online (Sandbox Code Playgroud)
app.module.ts
import { NgModule } from "@angular/core";
import { …Run Code Online (Sandbox Code Playgroud) 每当 canDeactivate() 返回 false 时,我都会遇到一些问题,它会更改窗口历史记录,因为它变为 true 并且如果我按下后退按钮。我正在导航到其他一些 URL 或应用程序本身之外。
请帮我
我想对不同的功能模块使用相同的布局(在app.module.ts 中定义),每个模块都有自己的路由。还有一个单独的登录/注册布局,没有侧面菜单、页眉和页脚。到目前为止,我试过这个:
//../app/app.component.html
<router-outlet></router-outlet> // here i want login and layout view.
Run Code Online (Sandbox Code Playgroud)
和一个布局组件:
//../app/layout.component.html
<header></header>
<side-menu></side-menu>
<router-outlet></router-outlet> // here i want layout views that would have side menu with them e.g. dashboard, inventory etc
<footer></footer>
Run Code Online (Sandbox Code Playgroud)
仪表板路由在 app.module.ts 中,但清单和其他模块有自己的模块和路由,如下所示:
//app.module.ts
const appRoutes: Routes = [
{ path: 'login', component: LoginComponent },
{
path: '',
component: LayoutComponent,
children: [
{ path: '', component: DashboardOne},
{ path: 'dashboardOne', component: DashboardOne},
{ path: 'dashboardTwo', component: DashboardTwo}
],
canActivate: [AuthGuard]
}
];
@NgModule({ …Run Code Online (Sandbox Code Playgroud) 使用 angular 4,我将带有空路径的路由重定向到导航栏组件。所以我添加了pathMatch: full这个条目并将其放在路由数组的顶部。
但我仍然收到以下错误:
zone.js:522 未处理的承诺拒绝:
路由配置无效:无法指定数组;
区域:根;
任务: Promise.then ;
值:ZoneAwareError {
__zone_symbol__error: Error: Invalid configuration of route '': Array cannot be specified
at Zone.run ( http://localhost:4200/polyfills.bundle.js:6405:43 ) [ => angular]
路由.component.ts
import {Route} from '@angular/router';
import { AppComponent } from './app.component';
import {NavbarComponent} from './navbar/navbar.component';
import {RegistrationComponent} from './registration/registration.component';
export const appRoutes:Route =[
{
path: '',
redirectTo: 'navbar',
pathMatch: 'full'
}, {
path: 'home',
component: NavbarComponent
}, {
path: 'navbar',
component: NavbarComponent …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Angular 8 上创建一条路由,其中某个路径具有公共和私有版本,因此如果我在 URL 中输入 /tracker,路由模块可以将我发送到私有/公共版本,具体取决于我是登录还是登录出去。
我已经尝试过使用 CanActivate 的 Guards,但是如果我返回 false,这只会停止导航,并且我特别需要两条路线具有相同的路径。这是我的路由模块:
path: '',
children: [
{
path: '',
canActivate: [AuthGuard],
component: TrackingListPrivateComponent
},
{
path: '',
component: TrackingListComponent
}
]
}
Run Code Online (Sandbox Code Playgroud)
我希望能够在注销时在 URL 上输入 /tracker 并导航到 TrackingListComponent,登录后在 URL 上输入 /tracker 并导航到 TrackingListPrivateComponent。
angular2-routing ×10
angular ×8
components ×1
javascript ×1
razor ×1
typescript ×1
url ×1
web-config ×1