【问题标题】:React-navigation change url but not view反应导航更改网址但不查看
【发布时间】:2021-08-06 20:58:25
【问题描述】:

我正在使用 React Native for Web 并在我的应用程序中实现了导航,但我无法导航下一个 - 使用浏览器按钮上一个,

浏览器地址栏的网址改变了,但无法改变视图。

我在网络/移动设备上都使用过React-Navigation,任何人都知道更好的方法,请指导我

//App.js 
import * as React from 'react';
import { View, Text,Button,Platform } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';

function HomeScreen({ navigation }) {

return (

    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <View style={{ marginVertical: 20 }}>
      <Text style={{fontWeight:'100',fontSize:30}}>Home Screen</Text>
      </View>
      
      
      <Button
        title="Go to Details Screen"
        onPress={() => navigation.navigate('Details')}
      />

      <View style={ {marginVertical:20}}>
        <Button  title="Go to Setting Screen" onPress={() => navigation.navigate('Setting')} />
      </View>
    </View>
  );
}


const Stack = createStackNavigator();

function App() {

  const linking = {
    prefixes: ['myurlhere://'],
    config: {

      screens: {
        Setting: 'Setting',
        Details: 'Details',
      },
    },
  };


  return (
    <NavigationContainer linking={linking} >
      <Stack.Navigator>
        <Stack.Screen name="Home" component={HomeScreen} options={{ headerShown: !isWeb, headerLeft:()=> null }} />
        <Stack.Screen name="Setting" component={Setting} options={{headerShown:!isWeb}}/>
        <Stack.Screen name="Details" component={Details} options={{headerShown:!isWeb}}/>
      </Stack.Navigator>
    </NavigationContainer>
  );
}

 [![//Setting Screen
    function Setting() {
      return (
        <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
        <Text style={{fontWeight:'100',fontSize:30}}>Setting Screen</Text>
        </View>
      );
    }
    //Details Screen
    function Details() {
      return (
        <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
         <Text style={{fontWeight:'100',fontSize:30}}>Detail's Screen</Text>
        </View>
      );
    }]
export default App;

【问题讨论】:

    标签: reactjs react-native react-router react-navigation-v5 react-native-web


    【解决方案1】:

    我也在研究。

    但这就是我的工作所在。

        const linking = {
          prefixes: ['http://localhost:19006/', 'mychat://'],
          config: {
            screens: {
              Home: '',
              Search: '?:id/Search',
            }
          },
        };
    
      return (
    
          <AppContext.Provider value={userSettings}>
                <NavigationContainer linking={linking}>
                  <StackContainer />
                </NavigationContainer>
          </AppContext.Provider>
      );
    

    【讨论】:

      猜你喜欢
      • 2020-12-26
      • 1970-01-01
      • 2021-11-14
      • 2017-06-29
      • 2020-11-12
      • 1970-01-01
      • 2020-07-21
      • 2019-07-24
      • 1970-01-01
      相关资源
      最近更新 更多