gpt4 book ai didi

angular - 为什么直接导航到这条路线不匹配?

转载 作者:太空狗 更新时间:2023-10-29 17:19:13 27 4
gpt4 key购买 nike

备案:这是使用当前相当新的 "@angular/router": "3.0.0-alpha.8" ,路由定义在帖子的底部。

当尝试在我的应用程序中导航时,行为会有所不同,具体取决于我是直接输入 URL 还是通过链接输入:

  • 工作:输入http://localhost:9292在地址栏中,正确转发到 http://localhost:9292/about
  • 有效: 直接导航到 http://localhost:9292/about通过地址栏
  • 有效:如果我导航到 http://localhost:9292/about/projects通过 <a>标记,在 FrontComponent 的上下文中和 [routerLink]="['projects']"属性,路由工作得很好。
  • 损坏: 直接导航到 http://localhost:9292/about/projects导致以下错误消息(缩短的 Stacktrace):

    Unhandled Promise rejection: Cannot match any routes: 'projects' ; Zone: angular ; Task: Promise.then ; Value: Error: Cannot match any routes: 'projects'
    Stack trace:
    applyRedirects/<@http://localhost:9292/node_modules/@angular/router/apply_redirects.js:29:34
    Observable.prototype.subscribe@http://localhost:9292/node_modules/rxjs/Observable.js:52:57

我可能在这里做错了什么?有什么方法可以查看错误消息中所有被拒绝的路由吗?

编辑 因为这已经被多次建议:我不怀疑这是服务器端问题。之前的路由通过 router-deprecated工作正常,HTML从失败的路线提供服务看起来很好。但以防万一,这是相关的服务器端路由代码( rubysinatra ):

# By now I have too often mistakenly attempted to load other assets than
# HTML files from "user facing" URLs, mostly due to paths that should have
# been absolute but weren't. This route attempts to catch all these
# mistakes rather early, so that the show up as a nice 404 error in the
# browsers debugging tools
get /^\/(about|editor)\/.*\.(css|js)/ do
halt 404, "There are no assets in `editor` or `about` routes"
end

# Matching the meaningful routes the client knows. This enables navigation
# even if the user submits a "deep link" to somewhere inside the
# application.
index_path = File.expand_path('index.html', settings.public_folder)
get '/', '/about/?*', '/editor/*' do
send_file index_path
end

# Catchall for everything that goes wrong
get '/*' do
halt 404, "Not found"
end

我不怀疑这是由于错误的路由定义(路由确实通过链接工作),但为了完整起见,这些是路由:

front/front.routes.ts:

export const FrontRoutes : RouterConfig = [
{
path: '',
redirectTo: '/about',
terminal: true
},
{
path : 'about',
component: FrontComponent,
children : [
{ path: 'projects', component: ProjectListComponent},
{ path: '', component: AboutComponent},
]
}
]

editor/editor.routes.ts:

export const EditorRoutes : RouterConfig = [
{
path: "editor/:projectId",
component : EditorComponent,
children : [
{ path: '', redirectTo: 'settings', terminal: true},
{ path: 'settings', component : SettingsComponent },
{ path: 'schema', component : SchemaComponent },
{ path: 'query/create', component : QueryCreateComponent },
{ path: 'query/:queryId', component : QueryEditorComponent },
{ path: 'page/:pageId', component : PageEditorComponent },
]
}
]

app.routes.ts:

import {EditorRoutes}                   from './editor/editor.routes'
import {FrontRoutes} from './front/front.routes'

export const routes : RouterConfig = [
...FrontRoutes,
...EditorRoutes,
]

export const APP_ROUTER_PROVIDERS = [
provideRouter(routes)
]

最佳答案

"/" 设置为 index.htmlbase 标记的值,以使路由器正确解析子路径。这是 not in line with the offical docs但似乎有效。

关于angular - 为什么直接导航到这条路线不匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38039294/

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