我有一个客户端web应用程序,它为两种帖子类型加载:/tutorial
和/dashboard
. WordPress路由可以很好地用于各个帖子:/tutorial/tutorial-1
和/dashboard/dashboard-1
.
然而,在我的客户端应用程序中,我想处理额外的路由片段:/tutorial/tutorial-1/quiz
. 我的React路由器在加载时可以很好地处理URL,但是直接链接的WordPress会给出404,因为虽然/tutorial/tutorial-1
存在,它无法匹配最后一个片段。
我假设我需要重写规则,但我已经很久没有为Apache编写这些规则了。基本上我需要匹配/[post-type]/*
路由到立柱类型。
按要求进行岗位类型登记:
$args = array (
\'label\' => esc_html__( \'Tutorials\', \'tutorial\' ),
\'labels\' => array(
\'menu_name\' => esc_html__( \'Tutorials\', \'tutorial\' ),
\'name_admin_bar\' => esc_html__( \'Tutorial\', \'tutorial\' ),
\'add_new\' => esc_html__( \'Add new\', \'tutorial\' ),
\'add_new_item\' => esc_html__( \'Add new Tutorial\', \'tutorial\' ),
\'new_item\' => esc_html__( \'New Tutorial\', \'tutorial\' ),
\'edit_item\' => esc_html__( \'Edit Tutorial\', \'tutorial\' ),
\'view_item\' => esc_html__( \'View Tutorial\', \'tutorial\' ),
\'update_item\' => esc_html__( \'Update Tutorial\', \'tutorial\' ),
\'all_items\' => esc_html__( \'All Tutorials\', \'tutorial\' ),
\'search_items\' => esc_html__( \'Search Tutorials\', \'tutorial\' ),
\'parent_item_colon\' => esc_html__( \'Parent Tutorial\', \'tutorial\' ),
\'not_found\' => esc_html__( \'No Tutorials found\', \'tutorial\' ),
\'not_found_in_trash\' => esc_html__( \'No Tutorials found in Trash\', \'tutorial\' ),
\'name\' => esc_html__( \'Tutorials\', \'tutorial\' ),
\'singular_name\' => esc_html__( \'Tutorial\', \'tutorial\' ),
),
\'public\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_nav_menus\' => true,
\'show_in_admin_bar\' => false,
\'show_in_rest\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'has_archive\' => true,
\'query_var\' => true,
\'can_export\' => true,
\'rewrite_no_front\' => false,
\'supports\' => array(
\'title\',
\'editor\',
\'thumbnail\',
\'excerpt\',
\'comments\',
\'revisions\',
),
\'description\' => \'A tutorial\',
\'menu_position\' => 20,
\'menu_icon\' => \'dashicons-exerpt-view\',
\'rewrite\' => true,
\'show_in_graphql\' => true,
\'graphql_single_name\' => \'tutorial\',
\'graphql_plural_name\' => \'tutorials\',
);
register_post_type( \'tutorial\', $args );