Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[go_router] state params missing after refresh on web #106312

Copy link
Copy link
Open
@Fintasys

Description

@Fintasys
Issue body actions

I've noticed an issue that when I refresh on web, the state.params in navigatorBuilder are missing even tho the location is set correctly.

Example:

Pattern: /:page
Url: localhost:4444/#/2

Result:

  • location = /2
  • state.params['page'] = null

Expected Result:

  • location = /2
  • state.params['page'] = 2
Code Example
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

void main() {
  runApp(MyApp());
}

final routes = [
  GoRoute(
    path: '/',
    builder: (context, state) => const Page(
      number: "1",
    ),
  ),
  GoRoute(
    path: '/:page',
    builder: (context, state) => Page(number: state.params["page"] ?? "1"),
  ),
];

class MyApp extends StatelessWidget {
  final _router = GoRouter(
      routes: routes,
      navigatorBuilder: (
        BuildContext context,
        GoRouterState state,
        Widget child,
      ) {
        print(state.location); // -> /2
        print(state.params); // -> null :( expected: { 'page': '2' }
        return child;
      });

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routeInformationProvider: _router.routeInformationProvider,
      routeInformationParser: _router.routeInformationParser,
      routerDelegate: _router.routerDelegate,
    );
  }
}

class Page extends StatelessWidget {
  const Page({Key? key, required this.number}) : super(key: key);
  final String number;

  @override
  Widget build(BuildContext context) {
    return Center(
        child: Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        Text("Page $number"),
        ElevatedButton(
            onPressed: () {
              final next = (int.tryParse(number) ?? 1) + 1;
              context.go("/$next");
            },
            child: Text("Next"))
      ],
    ));
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listImportant issues not at the top of the work listfound in release: 3.0Found to occur in 3.0Found to occur in 3.0found in release: 3.1Found to occur in 3.1Found to occur in 3.1has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: go_routerThe go_router packageThe go_router packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-frameworkOwned by Framework teamOwned by Framework team

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.