angular - 路由不起作用我的代码有什么问题
问题描述
我的 app-routing.module.ts 中有这条路线缺少一些东西,因为当我转到此页面时
我收到错误,但是当我去这里时它可以工作
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { SearchBooksComponent } from './search-books/search-books.component';
const routes: Routes = [
{
path: '',
redirectTo: '/search',
pathMatch: 'full'
},
{
path: 'search',
component: SearchBooksComponent
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
路线有什么问题?
这是我的 app.yaml
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /
static_files: dist/index.html
upload: dist/index.html
- url: /
static_dir: dist
解决方案
您应该重定向到search
而不是/search
:
const routes: Routes = [
{
path: '',
redirectTo: 'search',
pathMatch: 'full'
},
{
path: 'search',
component: SearchBooksComponent
}
];
仅当两条路线发生冲突时,路线顺序才重要,例如search
和**
。两条路线都将search
匹配,第一个获胜。
您可以像这样使用哈希定位策略。这个问题也解释了路径位置策略。
推荐阅读
- delphi - 如何忽略 TWebBrowser 中的加速字符(设计模式)
- python - Twitter+Apache Kafka+ Spark 结构化流不起作用
- java - 从 Java docker 容器连接到 MS SQL Server(HA,Always On)时的连接重置问题
- php - 如果 SQL 中的数据为真,则回显 html
- html - 将文本框限制为字段宽度
- php - 在heroku中找不到带有semantic-ui-css icon.woff2 404的Laravel
- javascript - 如何聚焦 Material UI 的 InputLabel?
- javascript - 使用添加按钮添加两个依赖选择
- kubernetes - 使用 Kubernetes 为 GIS 应用程序调整资源大小
- php - Laravel Nova 图像存储名称问题